I am trying to generate several violin plots in one, using seaborn. The dataframe I use includes several categorical values in one column (to be used on the x-axis), with an array of values for each categorical value (to be used to create the violin plot for each categorical value). A small working example would be this:
foo = pd.DataFrame(columns =['Names','Values'])
for i in range(10):
foo.loc[i] = ['no'+str(i),np.random.normal(i,2,10)]
But when trying
sns.violinplot(x='Names', y='Values', data=foo)
I get the following error
ValueError: Neither the
x
nory
variable appears to be numeric.
Now I could be hacky and just separate the array across several rows as such:
foo = pd.DataFrame(columns =['Names','Values'])
for i in range(3):
bar = np.random.normal(i,2,10)
for j,b in enumerate(bar):
foo.loc[i*10+j] = ['no'+str(i),b]
which yields the plot I want:
But I'm guessing there is a more simple solution to this, without needing to restructure my dataframe.