''' 操作excel 1 选中区域,点击插入 - 柱状图 2 选中区域,开始 - 排序和筛选 - 自定义排序 ''' import pandas as pd import matplotlib.pyplot as plt if __name__ == '__main__': students = pd.read_excel("C:/Users/123/Desktop/pandas/009_柱状图/Students.xlsx") print(students.head) # 排序 : 倒序 students.sort_values(by="Number", inplace=True, ascending=False) # 方法一 # students.plot.bar(x = "Field", y = "Number", color="orange", title = "international Students by Field") # 方法二 plt.bar(students.Field, students.Number, color="orange") plt.xticks(students.Field, rotation = "90") # 标签 : 90度 plt.xlabel("Field") # x轴名称 plt.ylabel("Number") # y轴名称 plt.title("International Students by Field", fontsize = 16) # 显示标签完整 plt.tight_layout() # 显示图片 plt.show()