实现excel表中柱状图的功能,并按金额排序。
引入matplotlib.pyplot模块。
下面是用pandas画的图,excel中出现中文可能会出现报错。
import pandas as pd
import matplotlib.pyplot as plt
ct_excel=pd.read_excel('F:/Practice/py/practise_08.xlsx')
# print(ct_excel)
ct_excel.sort_values(by='consume',inplace=True,ascending=False)
ct_excel.plot.bar(x='name',y='consume',color='orange',title='consumer’s consumption')
#----------------以上pandas
plt.tight_layout() #紧凑型的布局,标题可以显示全部
plt.show()
下边用到刚才导入的matplotlib.pyplot模块,同样实现上边的功能
import pandas as pd
import matplotlib.pyplot as plt
ct_excel=pd.read_excel('F:/Practice/py/practise_08.xlsx')
# print(ct_excel)
ct_excel.sort_values(by='consume',inplace=True,ascending=False)
plt.bar(ct_excel.name