1. #-*- coding: utf-8 -*-
    2. #菜品盈利数据 帕累托图
    3. from __future__ import print_function
    4. import pandas as pd
    5. #初始化参数
    6. dish_profit = '../data/catering_dish_profit.xls' #餐饮菜品盈利数据
    7. data = pd.read_excel(dish_profit, index_col = u'菜品名')
    8. data = data[u'盈利'].copy()
    9. # data.sort(ascending = False)
    10. # AttributeError: 'Series' object has no attribute 'sort'
    11. data.sort_index(ascending = False) # 版本问题
    12. import matplotlib.pyplot as plt #导入图像库
    13. plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签
    14. plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
    15. plt.figure()
    16. data.plot(kind='bar')
    17. plt.ylabel(u'盈利(元)')
    18. p = 1.0*data.cumsum()/data.sum()
    19. p.plot(color = 'r', secondary_y = True, style = '-o',linewidth = 2)
    20. plt.annotate(format(p[6], '.4%'), xy = (6, p[6]), xytext=(6*0.9, p[6]*0.9),
    21. arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2")) #添加注释,即85%处的标记。这里包括了指定箭头样式。
    22. plt.ylabel(u'盈利(比例)')
    23. plt.show()

    image.png