How to get different titles for each of the subplots in seaborn

Viewed 1762

I am unable to get Title/X-Label & Y-Label for the first box-plot. The second BoxPlot is giving me the labels/titles. What can i improve?

fig, (ax1,ax2) =plt.subplots(1,2,figsize=(30,15))

sns.boxplot(y = 'CVotesUS', x = 'IFUS', data = movies, ax=ax1)

plt.title('US Votes')

plt.xlabel('US & Non-US Movies')

plt.ylabel('US Voters')

sns.boxplot(y = 'CVotesnUS', x = 'IFUS', data = movies, ax=ax2)

plt.title('Non-US Votes for US and Non-US Movies')

plt.xlabel('US & Non-US Movies')

plt.ylabel('Non-US Voters')

These are the BoxPlots

1 Answers

Use ax1 and ax2 for setting titles, labels not plt.

fig, (ax1,ax2) =plt.subplots(1,2,figsize=(30,15))

sns.boxplot(y = 'CVotesUS', x = 'IFUS', data = movies, ax=ax1)

ax1.set_title('US Votes')

ax1.set_xlabel('US & Non-US Movies')

ax1.set_ylabel('US Voters')

sns.boxplot(y = 'CVotesnUS', x = 'IFUS', data = movies, ax=ax2)

ax2.set_title('Non-US Votes for US and Non-US Movies')

ax2.set_xlabel('US & Non-US Movies')

ax2.set_ylabel('Non-US Voters')

For demonstration, I have kept sns.boxplot() empty

enter image description here

Related