Skip to main content

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

SignatureDescription
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

OptionTypeDescription
namestringSeries name shown in legend and tooltip.
color_bystringColor mapping: 'series' (different color for each) or 'data' (different color for each data element).
clipbooleanClip 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

OptionTypeDescription
bar_widthnumber or stringBar width in pixels or as a percentage string (e.g. '50%').
bar_max_widthnumber or stringMaximum bar width.
bar_min_widthnumber or stringMinimum bar width.
bar_min_heightnumberMinimum bar height to ensure thin bars remain visible.
bar_gapstringGap 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)

OptionTypeDescription
colorColorFill color of the background bar.
border_colorColorColor of the background bar’s border.
border_widthnumberWidth of the background bar’s border in pixels.
border_typestringStyle of the border; options include 'solid', 'dashed', or 'dotted'.
opacitynumberOpacity of the background bar, ranging from 0 (fully transparent) to 1 (fully opaque).
shadow_blurnumberBlur radius of the shadow applied to the background bar.
shadow_colorColorColor 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.

OptionTypeDescription
colorColorFill color of the bar. Overrides the default series color.
border_colorColorColor of the bar’s border.
border_widthnumberWidth of the bar’s border in pixels.
border_typestringStyle of the border; options include 'solid', 'dashed', or 'dotted'.
shadow_blurnumberBlur radius of the shadow applied to the bar.
shadow_colorColorColor of the shadow applied to the bar.
shadow_offset_xnumberHorizontal offset of the shadow in pixels.
shadow_offset_ynumberVertical offset of the shadow in pixels.
opacitynumberOpacity 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.

OptionTypeDescription
showbooleanEnable or disable labels for each bar.
positionstring or ListPosition of the label relative to the bar; common values include 'top', 'bottom', 'left', 'right', 'inside', 'insideTop', 'insideBottom', 'insideLeft', and 'insideRight'.
distancenumberDistance in pixels between the label and the bar edge (applies to outside positions).
rotatenumberRotation angle of the label text in degrees. Positive values rotate clockwise.
colorColorText color of the label.
font_sizenumberFont size of the label text in pixels.
font_weightstring or numberFont weight of the label text (e.g. 'normal', 'bold', 400, 700).
font_familystringFont family used for the label text.
font_stylestringFont style of the label text (e.g. 'normal', 'italic', 'oblique').
alignstringHorizontal text alignment inside the label box ('left', 'center', 'right').
vertical_alignstringVertical 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")