python matplotlib图缩放xaxis和标签

时间:2018-06-25 17:13:15

标签: python matplotlib

我的输出有点混乱。我希望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()

输出:

output graph

1 个答案:

答案 0 :(得分:0)

  1. 设置xticks的语法是:

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

    **kwargs可以包含Text properties,其中fontproperties关键字可以为您分配FontProperties对象。

    因此您可以尝试以下操作:

    fp = matplotlib.font_manager.FontProperties(family="sans-serif", size=8)  # play around with the formatting
    plt.xticks(rotation=90, fontproperties=fp)
    
  2. 另一种可能性是增加整个图的大小,具体说明如下:How do you change the size of figures drawn with matplotlib?