plotter.drawables.bars¶
class BarChart(Drawable)¶
Class for creating a bar chart.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
NArray1D[Any] | The array containing the x positions of the bars. |
heights |
NArray1D[Any] | The array containing the heights of the bars. |
yerr |
ErrorBars | None, optional | The uncertainty on the bar heights: a float (identical for every bar), an array of shape (N,) (symmetric, one per bar), or an array of shape (N, 2) (asymmetric, one (low, high) pair of error sizes per bar). |
Raises:
| Type | Description |
|---|---|
| ValueError | If x and heights do not have the same dimensions. |
| ValueError | If yerr as an array is not of shape (N,) or (N, 2), with N the number of bars. |
Defined attributes:
label_name: ClassVar[str]draw_kwargs: ClassVar[frozenset[str]]x: NArray1D[Any]heights: NArray1D[Any]yerr: ErrorBars | None
Methods¶
draw¶
draw(self, canvas: Canvas | ZoomInset, plot_n: int=0, label: str | None=None, bar_labels: bool | dict[str, Any]=False, **kwargs) -> None
Draws the bar chart on the canvas.
Args:
| Name | Type | Description |
|---|---|---|
canvas |
Canvas | ZoomInset | The canvas (or zoom-inset panel) to draw the bar chart on. |
plot_n |
int, optional | The index of the subplot to draw on. Defaults to 0. |
label |
str, optional | The label for the bar chart in the legend. Defaults to None. |
bar_labels |
bool | dict[str, Any], optional | If truthy, writes a text label above each bar via Axes.bar_label. Pass True for the default behavior (each bar's height, formatted with matplotlib's "%g" format), or a dict of keyword arguments forwarded straight through to Axes.bar_label -- e.g. {"labels": \[...\]} for custom per-bar text, or "fmt"/"label_type"/"padding"/any Text styling kwarg. Defaults to False. |
Keyword Arguments:
| Name | Type | Description |
|---|---|---|
bottom |
float | NArray1D[Any] | The y-coordinate(s) of each bar's base. Pass the previous series' (cumulative) heights to stack bar charts on top of each other -- see plotter.helpers.useful_functions.stack_bottoms for computing this across more than two series. Defaults to 0. |
width |
float | The width of the bars. Defaults to 0.8. |
color |
str | The Matplotlib color of the bars. Defaults to "steelblue". |
alpha |
float | The transparency of the bars. Defaults to 0.9. |
err_color |
str | The color of the error bars. Defaults to "black". |
err_width |
float | The width of the error bars. Defaults to 1.5. |
err_capsize |
float | The size of the error bar ticks. Defaults to 3. |
lw |
float | The width of the bar edges. Defaults to 0. |
edgecolor |
str | The color of the bar edges. Defaults to "midnightblue". |
Raises:
| Type | Description |
|---|---|
| ValueError | If plot_n is out of range for canvas. |
| TypeError | If a keyword argument not listed above is given. |