import matplotlib.pyplot as plt
stu = pd.read_excel('D:\Students.xlsx')
柱状图,设置x,y轴,颜色,标题
stu.plot.bar(x='Field',y='Number',color = 'orange',title='Fig')
紧凑型显示,让每个元素的名字显示出来
plt.tight_layout()
plt.show()
另解,用plt直接做,更为灵活。
plt.bar(students['Field'], students['Number'], color='orange', width=0.7)
plt.xticks(students['Field'], rotation='90') #rotation旋转轴名称的方向
plt.title('International Student by Field', fontsize=16)
plt.xlabel('Field') #设定x轴
plt.ylabel('Number') #设定优酷轴
plt.tight_layout()
plt.show()