Reputation: 25
So unfortunately I am facing the problem right now, that I plotted two subplots next to each other but would like to get the full name of the months instead of the number (this happened because in the data frame the months are given as a number) on the x-axis[![enter image description here] Can anybody give me advice how to change it?
Following the code: '''
f, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(14,6))
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
sns.set_style('darkgrid')
custom_palette=['orange','purple']
sns.set_palette(custom_palette)
sns.countplot(x='month',hue='year', data=continent_3[continent_3["is_booking"] == 1], ax=ax1)
sns.pointplot(x='month',y='is_booking',hue='year', ci=None, data=continent_3, ax=ax2)
ax1.set(xlabel = 'Month', ylabel = 'Bookings')
ax2.set(xlabel = 'Month', ylabel = 'Bookings')
ax1.set_title('Absoulute Number of Bookings', y=1.03, fontsize=17)
ax2.set_title('Conversion Rate', y=1.03, fontsize=17)
ax1.get_legend().remove()
ax2.legend(loc='center right', bbox_to_anchor=(1.25, 0.85), ncol=1)
plt.subplots_adjust(wspace = 0.2)
'''
Upvotes: 0
Views: 5579
Reputation: 2192
You can use the set_xticklabels
method from matplotlib.axes.Axes.
f, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(14,6))
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
sns.set_style('darkgrid')
custom_palette=['orange','purple']
sns.set_palette(custom_palette)
sns.countplot(x='month',hue='year', data=continent_3[continent_3["is_booking"] == 1], ax=ax1)
sns.pointplot(x='month',y='is_booking',hue='year', ci=None, data=continent_3, ax=ax2)
ax1.set(xlabel = 'Month', ylabel = 'Bookings')
ax1.set_xticklabels(months)
ax2.set(xlabel = 'Month', ylabel = 'Bookings')
ax2.set_xticklabels(months)
ax1.set_title('Absoulute Number of Bookings', y=1.03, fontsize=17)
ax2.set_title('Conversion Rate', y=1.03, fontsize=17)
ax1.get_legend().remove()
ax2.legend(loc='center right', bbox_to_anchor=(1.25, 0.85), ncol=1)
plt.subplots_adjust(wspace = 0.2)
Upvotes: 2