010_分组柱图
import pandas as pd import matplotlib.pyplot as plt if __name__ == '__main__': students = pd.read_excel("C:/Users/123/Desktop/pandas/010_叠加柱状图_水平柱状图/Students.xlsx") print(students.head) # 排序 : 倒序 students.sort_values(by=["2017", "2016"], inplace=True, ascending=False) print(students.head) # 方法一 students.plot.bar(x = "Field", y = ["2017", "2016"], color=["orange", "red"], title = "international Students by Field") plt.title("International Students by Field", fontsize = 16, fontweight = "bold") # 设置title plt.xlabel("Fieled", fontweight = "bold") # x轴名称 plt.ylabel("Number", fontweight = "bold") # y轴名称 # 设置文字 - 对齐 ax = plt.gca() ax.set_xticklabels(students['Field'], rotation = 45, ha = "right") plt.tight_layout() # 显示标签完整 # 显示图片 plt.show()