簡體   English   中英

python matplotlib圖縮放xaxis和標簽

[英]python matplotlib plot scaling xaxis and labels

我的輸出有點混亂。 我希望x軸上的狀態可見

performance0 = denied_states['STATE'].value_counts().sort_index()
performance1 = certified_states['STATE'].value_counts().sort_index() 
performance2 = cw_states['STATE'].value_counts().sort_index()
performance3 = w_states['STATE'].value_counts().sort_index()
plt.plot( performance0, label = 'Denied')
plt.plot( performance1, label = 'Certified')
plt.plot( performance2, label = 'Certified-Withdrawn')
plt.plot( performance3, label = 'Withdrawn')
plt.xticks(rotation=90)
plt.xlabel('States')

plt.ylabel('Applications')
plt.title('No. of Applicants status of H1B Visa based on states')
plt.legend()
plt.show()

輸出:

輸出圖

  1. 設置xticks語法是:

     xticks(locs, [labels], **kwargs) # Set locations and label 

    **kwargs可能包含Text屬性 ,其中包括fontproperties關鍵字,您可以為其分配FontProperties對象。

    因此,您可以嘗試執行以下操作:

     fp = matplotlib.font_manager.FontProperties(family="sans-serif", size=8) # play around with the formatting plt.xticks(rotation=90, fontproperties=fp) 
  2. 另一種可能性是增加整個繪圖的大小,具體方法如下: 如何更改用matplotlib繪制的圖形的大小?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM