簡體   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