What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Pass one data vector per group to Axes.violinplot(), then use matching positions and tick labels to place and identify the violins. For example:
import matplotlib.pyplot as plt
samples = [group_a, group_b, group_c]
positions = [1, 2, 3]
fig, ax = plt.subplots()
parts = ax.violinplot(samples, positions=positions, showmedians=True)
ax.set_xticks(positions, labels=['A', 'B', 'C'])
ax.set_ylabel('Observed value')
ax.set_title('Distribution by group')
plt.show()
Each item in samples should be a one-dimensional vector of observations. Replace the example group variables and labels with your data and category names.
How Matplotlib maps data to violins
Axes.violinplot(dataset, ...) draws one violin for each vector in a sequence. It can also take a two-dimensional array and draw one violin per column; a single one-dimensional array produces one violin. Non-finite and masked values are ignored. See the Axes.violinplot API documentation.
The default positions are 1 through the number of datasets. Set positions when you need different coordinates, and set ticks at those same coordinates so the category names stay aligned.
#1 Best Overall
Set up category spacing and labels
For vertical violins, positions are x coordinates; for horizontal violins, they are y coordinates. You can leave gaps to separate groups visually, as in Matplotlib’s violin plot gallery example:
positions = [1, 2, 4, 5, 7, 8]
parts = ax.violinplot(samples, positions=positions, showmedians=True)
ax.set_xticks(positions, labels=['A1', 'A2', 'B1', 'B2', 'C1', 'C2'])
Use one label for every position. For horizontal plots, put the labels on the y axis instead:
Rank #2
positions = [1, 2, 3]
parts = ax.violinplot(
samples,
positions=positions,
orientation='horizontal',
showmedians=True,
)
ax.set_yticks(positions, labels=['A', 'B', 'C'])
ax.set_xlabel('Observed value')
Use orientation='horizontal' for horizontal violins. The older vert parameter has been deprecated since Matplotlib 3.10, so new code should use orientation. Check the API documentation for the parameters supported by your installed version.
Choose summary marks to display
Matplotlib can overlay summary markers on each violin. By default, extrema are shown, while means and medians are hidden. Enable the marks you need with the corresponding options:
Free tools Windows power users keep installed
One-click scans. No signup required.
parts = ax.violinplot(
samples,
showmeans=True,
showextrema=True,
showmedians=True,
)
Quantiles can also be supplied through the API’s quantiles parameter. These markers describe aspects of the data alongside its density shape; choose them to suit the comparison rather than adding every mark automatically.
Adjust density rendering carefully
A violin’s outline is a kernel density estimate. The bw_method parameter controls its bandwidth, and points controls the number of evaluation points used to draw the estimate. The API accepts 'scott', 'silverman', a float, or a callable for bw_method. Matplotlib’s gallery illustrates different bandwidth and point-count choices, but it does not establish one setting as right for every dataset. Inspect the resulting shape against the observations and use a consistent approach when comparing groups.
Rank #4
Violin width represents density by default, not the number of observations. A wider shape should not be interpreted as a larger sample unless sample size is encoded separately.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Style the returned violins
violinplot() returns a dictionary of collections, including bodies for the filled shapes and collections for summary marks. You can style the bodies after plotting:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteBest Value
for body in parts['bodies']:
body.set_edgecolor('black')
body.set_linewidth(1)
body.set_alpha(0.7)
The official customization example also draws quartiles and whiskers over the violin bodies. Matplotlib 3.11 documentation includes facecolor and linecolor arguments; check your installed version before using these newer arguments. The returned-body styling approach lets you customize the filled shapes through their collection objects.
Choose between raw data and precomputed statistics
Use violinplot() when you have raw sample vectors and want Matplotlib to calculate the density representation. If you already have violin statistics, Axes.violin() accepts dictionaries with coords, vals, mean, median, min, and max, with optional quantiles. See Matplotlib’s violin plot comparison example and the violinplot API.
When a violin plot is useful
A violin plot shows a density trace and can reveal distribution shape. In Matplotlib’s comparison example, box plots identify points beyond 1.5 times the interquartile range as outliers, whereas the violin plots show the full data range. Choose the form that makes the features relevant to your data easiest to inspect; a violin’s shape does not replace an explicit sample-size indicator.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →




