Bar Series
The bar method of Figure adds a bar series, which is a chart of vertical rectangular bars. Bar charts are well suited for analyzing data sampled from a distribution or to visualize the relative amplitudes of quantities of interest.
Method Overloads
| Signature | Description |
|---|---|
bar(x, y [, options]) | Pass a list of x (bin positions) and y (bin heights) data. |
bar(points [, options]) | Pass a list of points [[x[0],y[0]],[x[1],y[1]], ...]. |
bar(options) | Pass an option. Data is specified through the "data" key ["data": [[x[0],y[0]],[x[1],y[1]], ...]]. Can also be used without data for formatting purposes. |
Quick examples
Figure()
.x_axis(["min": 0, "max": 11])
.bar([1, 2], [20, 35])
.bar([3,4], [10,2], ["color":"#91CC75"])
.bar([[5,11],[6,5]])
.bar([[7,8],[8,5]], ["color":"#cc75c5"])
.bar(["data":[[9,11],[10,5]], "color":"#75bfcc"])
.save("./figures/ex_bar_basic")
General
| Option | Type | Description |
|---|---|---|
name | string | Series name shown in legend and tooltip. |
color_by | string | Color mapping: 'series' (different color for each) or 'data' (different color for each data element). |
clip | boolean | Clip series that overflows the coordinate area. |
Quick examples
Figure()
.bar([1,2,3,4], [3,4,1,10], ["color_by":"data", "name": "color by data", "clip": true])
.bar([5,6,7,8], [3,4,1,10], ["color_by":"series", "name": "color by series", "clip": false])
.legend()
.save("./figures/ex_bar_general")
Bar Sizing
| Option | Type | Description |
|---|---|---|
bar_width | number or string | Bar width in pixels or as a percentage string (e.g. '50%'). |
bar_max_width | number or string | Maximum bar width. |
bar_min_width | number or string | Minimum bar width. |
bar_min_height | number | Minimum bar height to ensure thin bars remain visible. |
bar_gap | string | Gap between bars in the same category (e.g. '30%', '-100%' for overlap). |
Quick examples
Figure()
.bar([1,2], [3,4], ["name": "width","bar_width":12])
.bar([3,4], [5,6], ["name": "max width","bar_max_width":12])
.bar([5.1,6.1], [5,0], ["name": "min width", "color_by": "series","bar_min_width":13, "bar_min_height": 10]) // Explicit control on the position of the bars
.bar(["bar_gap": "-50%"]) // Global option specifying the distance between overlapping bars of different series
.legend()
.save("./figures/ex_bar_sizing")
background_style(options)
| Option | Type | Description |
|---|---|---|
color | Color | Fill color of the background bar. |
border_color | Color | Color of the background bar’s border. |
border_width | number | Width of the background bar’s border in pixels. |
border_type | string | Style of the border; options include 'solid', 'dashed', or 'dotted'. |
opacity | number | Opacity of the background bar, ranging from 0 (fully transparent) to 1 (fully opaque). |
shadow_blur | number | Blur radius of the shadow applied to the background bar. |
shadow_color | Color | Color of the shadow applied to the background bar. |
Quick examples
Figure()
.bar([1,2,3], [4,5,6], [
"name": "dashed border",
"show_background": true,
"background_style": [
"color": "#6dc521",
"border_color": "#26e1d8",
"border_width": 2,
"border_type": "dashed",
"opacity": 0.5,
"shadow_blur": 10,
"shadow_color": "#367eac"
]
])
.bar([5,6,7], [6,4,5], [
"name": "solid border",
"show_background": true,
"background_style": [
"color": "#e51414",
"border_color": "#88a70c",
"border_width": 1,
"opacity": 0.6
]
])
.legend()
.save("./figures/ex_bar_background")
item_style(options)
Controls the visual style of each bar.
| Option | Type | Description |
|---|---|---|
color | Color | Fill color of the bar. Overrides the default series color. |
border_color | Color | Color of the bar’s border. |
border_width | number | Width of the bar’s border in pixels. |
border_type | string | Style of the border; options include 'solid', 'dashed', or 'dotted'. |
shadow_blur | number | Blur radius of the shadow applied to the bar. |
shadow_color | Color | Color of the shadow applied to the bar. |
shadow_offset_x | number | Horizontal offset of the shadow in pixels. |
shadow_offset_y | number | Vertical offset of the shadow in pixels. |
opacity | number | Opacity of the bar, ranging from 0 (fully transparent) to 1 (fully opaque). |
Quick examples
Figure()
.bar([1,2,3], [4,5,6], [
"name": "with shadow",
"item_style": [
"color": "#5470c6",
"border_color": "#06609c",
"border_width": 2,
"border_type": "solid",
"border_radius": 6,
"shadow_blur": 8,
"shadow_color": "rgba(199, 22, 22, 0.9)",
"shadow_offset_x": 2,
"shadow_offset_y": 4,
"opacity": 0.9
]
])
.bar([5,6,7], [6,4,5], [
"name": "without shadow",
"item_style": [
"color": "#91cc75",
"opacity": 0.8
]
])
.legend()
.save("./figures/ex_bar_item_style")
label(options)
Labels rendered on or near each bar.
| Option | Type | Description |
|---|---|---|
show | boolean | Enable or disable labels for each bar. |
position | string or List | Position of the label relative to the bar; common values include 'top', 'bottom', 'left', 'right', 'inside', 'insideTop', 'insideBottom', 'insideLeft', and 'insideRight'. |
distance | number | Distance in pixels between the label and the bar edge (applies to outside positions). |
rotate | number | Rotation angle of the label text in degrees. Positive values rotate clockwise. |
color | Color | Text color of the label. |
font_size | number | Font size of the label text in pixels. |
font_weight | string or number | Font weight of the label text (e.g. 'normal', 'bold', 400, 700). |
font_family | string | Font family used for the label text. |
font_style | string | Font style of the label text (e.g. 'normal', 'italic', 'oblique'). |
align | string | Horizontal text alignment inside the label box ('left', 'center', 'right'). |
vertical_align | string | Vertical text alignment inside the label box ('top', 'middle', 'bottom'). |
Figure()
.bar([1,2,3], [4,5,6], [
"name": "top",
"label": [
"show": true,
"position": "top",
"color": "#e8700ee3",
"font_size": 14,
"font_weight": "bold"
]
])
.bar([5,6,7], [6,4,5], [
"name": "centered",
"label": [
"show": true,
"position": "inside",
"color": "#10b7ef",
"font_size": 12,
"rotate": 90,
"align": "center",
"vertical_align": "middle"
]
])
.legend()
.save("./figures/ex_bar_label")