Skip to content

Add box plot / violin plot (figure.boxplot()) #6

Description

@MoonFlowww

Summary

Add figure.boxplot() to display the five-number summary (min, Q1, median, Q3, max) of one or more data series, matching matplotlib's plt.boxplot().

Motivation

Box plots are the standard way to compare performance distributions across multiple implementations side-by-side without the noise of a full histogram. A single glance reveals median, spread, and outliers for each candidate.

Proposed API

// One box per series
figure.boxplot(impl_a.data(), impl_a.size(), 1.0).label("impl A");
figure.boxplot(impl_b.data(), impl_b.size(), 2.0).label("impl B");
figure.boxplot(impl_c.data(), impl_c.size(), 3.0).label("impl C");

// Or batch API:
figure.boxplot({impl_a, impl_b, impl_c}, {"impl A", "impl B", "impl C"});

The second positional argument is the X-center for the box.

Implementation Notes

Statistics to compute per series (single O(n log n) sort pass):

  • min, max — first/last element after sort
  • Q1, median, Q3 — index-based selection after sort (no full sort needed, nth_element)
  • Whiskers: 1.5 × IQR rule (Tukey); points beyond = outliers drawn as individual markers

Rendering (all via existing Canvas primitives):

  • Box: draw_rect() from Q1 to Q3 at fixed pixel width
  • Median line: draw_line() across the box at median Y
  • Whisker lines: thin vertical draw_line() from box edges to whisker tips + horizontal caps
  • Outliers: draw_circle() for each point beyond whiskers

Acceptance Criteria

  • Correct Q1/Q3/median/whisker/outlier computation
  • Box rendered with correct pixel dimensions
  • Outliers shown as markers
  • Multiple boxes on the same figure
  • Optional notched box variant (confidence interval around median)
  • Example: examples/boxplot.cpp

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions