Skip to content
Bar

Bar

A bar chart.

Bar

Usage

from dataviz_mojo import bar
from dataviz_mojo.plot import save
from dataviz_mojo.colors import SEAGREEN
from dataviz_mojo.theme import Theme

def main() raises:
    var categories: List[String] = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
    var values: List[Float64] = [12.0, 19.0, 8.0, 15.0, 22.0, -4.0, 6.0]

    var c = bar(categories, values, theme=Theme(mark_color=SEAGREEN))
    save(c, "docs/src/examples/out_bar.svg")

Diverging bars (color_by_sign)

Bar – Diverging bars (color_by_sign)

from dataviz_mojo import bar
from dataviz_mojo.plot import save
from dataviz_mojo.theme import Theme

def main() raises:
    var quarters: List[String] = ["Q1", "Q2", "Q3", "Q4", "Q5", "Q6"]
    var net_change: List[Float64] = [15.0, -8.0, 22.0, -3.0, 10.0, -12.0]

    var c_diverging = bar(quarters, net_change, theme=Theme(color_by_sign=True))
    save(c_diverging, "docs/src/examples/out_bar_diverging.svg")

Args:

  • categories: One bar per entry, in the given order.
  • values: Each bar’s height; negative values extend below the zero baseline automatically.
  • theme: Full styling knobs beyond this function’s own parameters (colors, margins, fonts, gridlines, …) – see Theme’s docstring.
  • width: Pixel width of the returned Plot (.size()).
  • height: Pixel height of the returned Plot (.size()).
  • title: The chart’s title, shown above the plot.
  • subtitle: A secondary line shown under the title.
  • x_title: The x-axis caption.
  • y_title: The y-axis caption.