Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

seaborn violin plot, how can I set labels?

Tags:

seaborn

I'm plotting a list of vectors as a sequence of violin plots. I'd use a pandas dataframe, but the lists are unequal lengths.

This works: python g = sns.violinplot (data=res, cut=0, inner='box')

where 'res' is a list of lists (each a vector of floats), where each vector should be turned into a violin. It is.

but the x axis is just labeled '0,1,2...'. Adding the parameter 'names=[0,1,2...]' is silently ignored.

like image 370
nbecker Avatar asked Oct 15 '25 04:10

nbecker


2 Answers

You can use the .set_xticklabels() method:

ax = sns.violinplot(data=res, cut=0, inner='box')
ax.set_xticklabels(['a','b','c'...])

Example:

import numpy as np, seaborn as sns

res = [i for i in (np.random.randn(3, 25))]
ax = sns.violinplot(data=res, cut=0, inner='box')
ax.set_xticklabels(['a','b','c'])

Results in:

enter image description here

like image 147
mechanical_meat Avatar answered Oct 18 '25 16:10

mechanical_meat


ax = sns.violinplot(data=rescaledX,   inner='quartile')
ax.set_xticklabels(bos.columns)
ax.set_title('Distribution of Boston Housing Data Set', fontsize=16);

Violin Plot of Boston Housing Data with Labeled Columns

like image 40
ricyoung Avatar answered Oct 18 '25 17:10

ricyoung