John
John

Reputation: 129

Display column names in seaborn boxplot

I have this code.

l = df.columns.values
number_of_columns=5
number_of_rows = len(l)-1/number_of_columns
plt.figure(figsize=(number_of_columns * 2, 5*number_of_rows))
for i in range(0,len(l)):
    plt.subplot(number_of_rows + 1, number_of_columns, i+1)
    sns.set_style('whitegrid')
    sns.boxplot(data=df[l[i]], color='green', orient='v')
    plt.tight_layout()

This is the output.

enter image description here

I want the output to display the column/feature name like the following image.

enter image description here

Can someone tell me how to do that?

Thanks

Upvotes: 1

Views: 2264

Answers (1)

ibarrond
ibarrond

Reputation: 7601

You should collect the matplotlib.axes object returned by sns.boxplot and add a name to its y-axis:

   #...
   ax = sns.boxplot(data=df[l[i]], color='green', orient='v')
   ax.set_ylabel(df.columns[i])
   #...

Upvotes: 1

Related Questions