import pandas as pd
import matplotlib.pyplot as plt
students = pd.read_excel('D:/output.xlsx', index_col='idx')
students.sort_values(by='M2019', inplace=True, ascending=True)
print(students)
# 设置柱状图
# 使用pandas绘图
students.plot.bar(x='Name', y=['M2018','M2019'], color=['orange','red'], title='Internation Students By Field')
plt.title('This is Internation Students by Field',fontsize=16, fontweight='bold')
plt.xlabel('Student Name', fontweight='bold')
plt.ylabel('Student Score', fontweight='bold')
# 拿到当前的x周
ax = plt.gca()
ax.set_xticklabels(students.Name, rotation='45', ha='right')
af = plt.gcf()
af.subplots_adjust(left=0.2, bottom=0.42)
#设置为紧凑型布局
#plt.tight_layout()
#显示图表
plt.show()
视频地址:https://www.bilibili.com/video/av88814463?p=10
来源:oschina
链接:https://my.oschina.net/ski/blog/3179482