Reputation: 2659
Why is the violin plot in matplotlib demanding non-standard inputs?
minimum non-working example
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots(3, 1)
ax[0].plot([3, 4, 5])
ax[1].boxplot([3, 4, 5])
ax[2].violin([3, 4, 5])
produces the first two plots but gives error for the third:
TypeError: 'int' object is not subscriptable
The following commands all produce errors
ax[2].violin([[3, 4, 5]])
ax[2].violin([[3], [4], [5]])
ax[2].violin(np.array([[3, 4, 5]]))
ax[2].violin(np.array([3, 4, 5]))
ax[2].violin([np.array([3, 4, 5])])
ax[2].violin([np.array([[3, 4, 5]])])
ax[2].violin([np.array([[3], [4], [5]])])
The doc simply states:
dataset : Array or a sequence of vectors.
The input data.
What format must I input for this function and why not accepting standard data vectors?
Upvotes: 1
Views: 291
Reputation: 1034
ax.violin
is different from plt.violinplot
. From the (actual) doc of ax.violin
:
ax.violin(vpstats, positions=None, vert=True, widths=0.5, showmeans=False, showextrema=True, showmedians=False)
(...)
vpstats : list of dicts
A list of dictionaries containing stats for each violin plot.
See https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.violin.html
Upvotes: 2