繁体   English   中英

重命名 x 刻度 / Seaborn

[英]Renaming the x ticks / Seaborn

所以不幸的是,我现在面临的问题是,我绘制了两个相邻的子图,但想获得月份的全名而不是数字(发生这种情况是因为在数据框中,月份是以数字形式给出的)在 x 轴上[?[在此处输入图像描述] 谁能给我建议如何更改它?

按照代码:'''

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) 

'''

先感谢您。 在此处输入图像描述

您可以使用matplotlib.axes.Axes中的set_xticklabels方法。

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) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM