1. 程式人生 > >貢獻度分析--帕累託圖

貢獻度分析--帕累託圖

#菜品盈利資料 帕累託圖
import pandas as pd

#初始化引數
dish_profit = 'catering_dish_profit.xls' #餐飲菜品盈利資料
data = pd.read_excel(dish_profit, index_col = '菜品名')
data = data['盈利'].copy()
data.sort_values(ascending = False)

import matplotlib.pyplot as plt #匯入影象庫
plt.rcParams['font.sans-serif'] = ['SimHei'] #用來正常顯示中文標籤
plt.figure() data.plot(kind='bar') plt.ylabel('盈利(元)') p = 1.0*data.cumsum()/data.sum() p.plot(color = 'r', secondary_y = True, style = '-o',linewidth = 2) plt.annotate(format(p[6], '.4%'), xy = (6, p[6]), xytext=(6*0.9, p[6]*0.9), arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2")) #添加註釋,即85%處的標記。這裡包括了指定箭頭樣式。
plt.ylabel('盈利(比例)') plt.show()

結果