Skip to content

Box Plot

box() over a long-form dataframe_mojo DataFrame (#743): one row per observation, with category naming each row’s group and value holding the number.

Box Plot

Usage

from dataviz import box
from dataviz import save
from dataviz.core.colors import ROYALBLUE
from dataviz import Theme

def main() raises:
    var regions: List[String] = ["US East", "EU West", "Asia Pacific"]
    # Illustrative API latency samples (ms), including one slow request
    # in each region so the whiskers and outlier points do real work.
    var latency_ms: List[List[Int]] = [
        [68, 72, 75, 71, 69, 74, 78, 73, 70, 76, 82, 77, 71, 69, 80, 74, 72, 75, 118, 67],
        [96, 102, 108, 99, 104, 111, 106, 101, 98, 115, 109, 103, 107, 100, 113, 105, 97, 110, 146, 102],
        [154, 162, 171, 158, 166, 179, 173, 160, 168, 181, 176, 164, 170, 157, 184, 169, 161, 175, 238, 165],
    ]

    var c = box(
        regions,
        latency_ms,
        title="Illustrative API Latency by Region",
        x_title="Region",
        y_title="Latency (ms)",
        theme=Theme(mark_color=ROYALBLUE),
    )
    save(c, "docs/src/examples/out_box.svg")

See Data shapes for shared input conventions.

Args:

  • df: The frame to read.
  • category: The string column naming each observation’s group.
  • value: The numeric column holding the observations.
  • theme: Full styling knobs beyond this function’s own parameters.
  • 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 line under the title.
  • x_title: The x-axis caption; defaults to category.
  • y_title: The y-axis caption; defaults to value.
  • horizontal: Draw the categories down the y axis instead.

Related

Related charts: Histogram · Letter-Value Plot

Relevant API: box