1. Excel
选中图标,插入,二维条形图,即可生成下图
2. Pandas
import pandas as pd
import matplotlib.pyplot as plt
students = pd.read_excel('C:/Tools/Python/Pandas/010/Students.xlsx')
students.sort_values(by='2017', inplace=True, ascending=False)
# 以最近的一年数据(2017)为基准进行降序排序
print(students)
students.plot.bar('Field', ['2016', '2017'], color=['orange', 'Red'])
plt.title('International Students by Field', fontsize=16)
plt.xlabel('Field', fontweight='bold')
plt.ylabel('Number', fontweight='bold')
plt.tight_layout()
ax = plt.gca() # gca = get current axis
ax.set_xticklabels(students['Field'], rotation=40, ha='right') # 重新铺x轴上的文字
# 默认旋转以文字的中心为基准进行旋转。 设置ha=’right‘,则设置为水平对齐,以右边的点为基准
plt.gcf().subplots_adjust(left=0.2, bottom=0.42)
# gcf:得到当前的figure 图形, 子图形的调整:左边留出20%的宽度,底部42%的宽度
plt.show()
来源:CSDN
作者:史努B
链接:https://blog.csdn.net/f2157120/article/details/103930703