Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Plotly · Class

go.Violin

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.

How it works

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.

Syntax

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)

Returns

A Plotly violin trace object suitable for insertion into a Figure.

Key points

  • Import plotly.graph_objects and instantiate go.Violin when constructing the trace directly.
  • A violin trace can be supplied as the data argument when creating a go.Figure.
  • The trace supports a visible mean line plus independent fill-color and opacity styling.
  • The documented example uses x0 to provide the category position or label for the trace.
  • The official page directs readers to the violin reference for the complete set of chart attributes and to px.violin() for the Express API.

Common mistakes

  • Use Graph Objects when you need lower-level control than Plotly Express provides; this class is the generic violin-trace option.

Example: Basic go.Violin trace

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.

When to use it

Low-level chart construction

Construct a distribution chart directly with Graph Objects.

Distribution diagnostics

Show quartiles and central tendency alongside the density shape.

Custom presentation

Style a violin trace for an interactive report or dashboard.

Interview questions

QWhat is 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.

QHow do you create a basic Plotly violin chart?

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.

QWhich options are demonstrated for controlling a violin trace?

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_objects
  • go.Figure
  • px.violin()
  • Violin chart attribute reference

Source: Violin plots in Python - Plotly. Checked 2026-10-15.