Skip to content

Violin

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

Violin

Usage

from dataviz import violin
from dataviz import save

def main() raises:
    var regions: List[String] = ["US East", "EU West", "Asia Pacific"]
    # The same illustrative latency sample used by box() and
    # beeswarm(), here emphasizing each region's distribution shape.
    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 = violin(
        regions,
        latency_ms,
        title="Illustrative API Latency by Region",
        x_title="Region",
        y_title="Latency (ms)",
    )
    save(c, "docs/src/examples/out_violin.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.
  • bandwidth: Kernel bandwidth; see the list overload.
  • scale_by_count: Scale each violin by its sample count.
  • width_fraction: Each violin’s share of its band.
  • 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: Letter-Value Plot · Beeswarm

Relevant API: violin