import pandas as pd import matplotlib.pyplot as plt if __name__ == '__main__': users = pd.read_excel("C:/Users/123/Desktop/pandas/011_叠加柱状图_水平柱状图/Users.xlsx") print(users.head) users["Total"] = users["Oct"] + users["Nov"] + users["Dec"] # 垂直叠加柱状图 # users.sort_values(by="Total", inplace=True, ascending=False) # 从多到少 # users.plot.bar(x = "Name", y = ["Oct", "Nov", "Dec"], stacked = True, title = "User Behavior") # 水平叠加柱状图 users.sort_values(by="Total", inplace=True, ascending=True) # 从多到少 users.plot.barh(x = "Name", y = ["Oct", "Nov", "Dec"], stacked = True, title = "User Behavior") plt.tight_layout() # 标签完整 plt.show()