Chart Gallery

/

Violin Plot in Python

Violin Plots in Python

A violin plot (also called a violin chart or violin graph) shows the full estimated density of a distribution as a mirrored curve, revealing multi-modal shapes that a box plot hides. With xy you build a violin plot in Python that compares several groups side by side and stays interactive — pan, zoom, and hover across every curve.

Jump to creating a violin plot, density resolution, or options.

Create a Violin Plot

Pass a list of arrays — one per group — to violin, and label each group with x. This is the minimal Python violin plot:

Density Resolution and Orientation

The bins option sets the resolution of the estimated density: more bins trace a finer curve, fewer bins smooth it out. Switch orientation to "horizontal" when group labels are long, and use width to control how wide each violin sits within its slot. The example above overlays a single-peak group against a two-peak group so the multi-modal shape is obvious.

Horizontal Violins at High Resolution

Raise bins for a finer density trace, turn the plot sideways with orientation="horizontal", and tune the fill with width and opacity.

Violin and Box Overlay

Compose violin and a narrow box on the same groups inside a neutral xy.chart(...) so each distribution shows its full density and its quartiles.

Violin Plot Options

OptionPurpose
binsDensity resolution — more bins trace a finer curve.
orientation"vertical" (default) or "horizontal".
widthWidth of each violin within its slot.
colorFill color (any CSS color).
opacityFill opacity from 0 to 1.

Pass column names with data= instead of arrays when your data is a table.

  • Box plots — summarize a distribution with quartiles instead of a full curve.
  • Histograms — bin one distribution into bars.

API Reference

xy.violin_chart

A violin chart composing `violin` marks.

Props

PropTypeDescription
*childrenComponent

Marks, axes, annotations, and chart chrome.

titleOptional[str]

Title shown above the plot.

widthint | str

Chart width in pixels or a CSS size such as ``"100%"``.

heightint | str

Chart height in pixels or a CSS size such as ``"100%"``.

paddingUnion[float, Sequence[float], None]

Plot margins, as one value or a sequence of side values. Use zero for an edge-to-edge sparkline.

dataTableLike

Chart-level data used by marks that omit their own ``data``.

class_nameOptional[str]

CSS class applied to the chart container.

class_namesOptional[dict[str, str]]

CSS classes keyed by stable chart DOM slot.

styleOptional[dict[str, StyleValue]]

Inline style overrides for the chart container.

stylesOptional[dict[str, dict[str, StyleValue]]]

Inline style mappings keyed by stable chart DOM slot.

on_hoverOptional[Callable[[dict], None]]

Callback receiving hover event payloads.

on_clickOptional[Callable[[dict], None]]

Callback receiving picked-mark click payloads.

on_brushOptional[Callable[[dict], None]]

Callback receiving brush event payloads.

on_selectOptional[Callable[[Selection], None]]

Callback receiving data-space selections.

on_view_changeOptional[Callable[[dict], None]]

Callback receiving viewport change payloads.

hoverOptional[bool]

Whether pointer movement emits hover events.

clickOptional[bool]

Whether picked marks emit click events.

selectOptional[bool]

Whether shift-drag box selection is enabled.

brushOptional[bool]

Whether brush selection is enabled.

crosshairOptional[bool]

Whether plot-aligned hover guides are shown.

navigationOptional[bool]

Whether browser pan and zoom navigation is enabled.

panOptional[bool]

Whether plain-drag panning is enabled.

pan_axesOptional[tuple[str, ...]]

Declared axis IDs translated by pan gestures.

zoomOptional[bool]

Whether viewport zoom is enabled.

default_drag_actionOptional[DefaultDragAction]

Initial action performed by a plain plot drag.

zoom_axesOptional[tuple[str, ...]]

Declared axis IDs changed by zoom gestures and controls.

zoom_limitsOptional[ZoomLimits]

Minimum and maximum magnification globally or by axis.

wheel_zoomOptional[bool]

Whether wheel and trackpad zoom is available.

box_zoomOptional[bool]

Whether box zoom is available as a drag action.

zoom_buttonsOptional[bool]

Whether modebar Zoom In/Out commands are available.

double_click_resetOptional[bool]

Whether double-click restores ``reset_axes``.

reset_axesOptional[tuple[str, ...]]

Declared axis IDs restored by reset.

link_groupOptional[str]

Identifier used to synchronize charts in the browser.

link_axesOptional[tuple[str, ...]]

Axes synchronized within the link group.

FAQ

How do I make a violin plot in Python?

Pass a list of arrays to xy.violin(...), one per group, inside xy.violin_chart(...) and render it. The density curves and axes are computed automatically.

What does the width of a violin plot mean?

The width at any level reflects the estimated density of values there — wider regions have more data. Use the width option to scale the whole violin within its slot.

How do I control the smoothness of a violin plot?

Set bins on violin. More bins trace a finer, more detailed density curve; fewer bins produce a smoother, simpler shape.

When should I use a violin plot instead of a box plot?

Use a violin plot when the shape matters — especially to reveal multi-modal distributions. A box plot only shows quartiles, so it hides multiple peaks.

Built with Reflex