Low-level chart construction
Construct a distribution chart directly with Graph Objects.
Plotly · Class
go.Violin creates a configurable interactive violin trace from plotly.graph_objects. Use it when the lower-level Graph Objects API is preferable to Plotly Express.
go.Violin is a low-level Plotly Graph Objects trace for visualizing a distribution. Pass observations through x or y, then configure its statistical overlays, appearance, orientation, and interaction before displaying it in a Figure.
go.Violin(arg=None, alignmentgroup=None, bandwidth=None, box=None, customdata=None, fillcolor=None, hoverinfo=None, hoveron=None, jitter=None, legendgroup=None, line=None, meanline=None, name=None, opacity=None, orientation=None, pointpos=None, points=None, scalemode=None, scalegroup=None, side=None, span=None, spanmode=None, text=None, uid=None, uirevision=None, unselected=None, visible=None, width=None, x=None, x0=None, y=None, y0=None, **kwargs)A Plotly violin trace object suitable for insertion into a Figure.
plotly.graph_objects and instantiate go.Violin when constructing the trace directly.data argument when creating a go.Figure.x0 to provide the category position or label for the trace.px.violin() for the Express API.import plotly.graph_objects as go
fig = go.Figure(go.Violin(
y=[1, 2, 2, 3, 4, 5],
box_visible=True,
meanline_visible=True,
line_color="black",
fillcolor="lightseagreen",
opacity=0.6,
x0="Values"
))
fig.show()Creates an interactive violin trace from numeric observations and enables an embedded box plot and mean line.
Construct a distribution chart directly with Graph Objects.
Show quartiles and central tendency alongside the density shape.
Style a violin trace for an interactive report or dashboard.
go.Violin and how is it used?go.Violin is a class in plotly.graph_objects used to construct a violin trace. Add the trace to a go.Figure, typically supplying observations with x or y.
Follow-up: How would you expose distribution details? Enable options such as box_visible and meanline_visible, then style the trace with its line, fill, and opacity settings.
A violin trace can be created with go.Violin(y=values, ...) and passed directly to go.Figure. The resulting figure is interactive and can be shown with fig.show().
Follow-up: How can you choose between the low-level and high-level APIs? Use px.violin() for a convenient starting point, and go.Violin when direct trace configuration is needed.
The documented example configures a vertical distribution with y, adds a visible box and mean line, and customizes the outline, fill color, opacity, and category label. These settings are trace attributes supplied to the constructor.
Follow-up: How would you build several distributions? Add multiple go.Violin traces to the same figure and configure their grouping or overlay behavior through the relevant trace and layout attributes.
plotly.graph_objectsgo.Figurepx.violin()Violin chart attribute reference