數據和內容是《Python數據分析與挖掘實戰》第3章中內容--貢獻度分析
講解怎樣在圖形中添加注釋
1 import pandas as pd 2 import matplotlib.pyplot as plt 3 df=pd.read_excel(r'E:\siren\Python dataAnalyst\chapter3\demo\data\catering_dish_profit.xls') 4 5 plt.rc('font', family='STXihei', size=10) 6 df['盈利'].plot(kind='bar') 7 plt.xticks([0,1,2,3,4,5,6,7,8,9],df['菜品名']) 8 plt.xlabel('菜品名') 9 plt.ylabel('盈利') 10 11 p=1.0*df['盈利'].cumsum()/df['盈利'].sum() 12 p.plot(color='r',secondary_y=True,style='-o') 13 plt.annotate(p[6],xy=(6,p[6]),xytext=(6*0.9,p[6]*0.9),arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0.5"))
#圖形中添加注釋 plt.annotate(y,xy,xytext,arrowprops,facecolor,headlength,headwidth,width) #y:注釋的內容; #xy:設置所要標注的位置坐標 #xytext:設置注釋內容顯示的起始位置 # arrowprops 用來設置箭頭 # facecolor 設置箭頭的顏色 # headlength 箭頭的頭的長度 # headwidth 箭頭的寬度 # width 箭身的寬度
#關於pandas中plot命令總結 p.plot(color,style,secondary_y) #參數secondary_y:布爾值或序列,默認為True;解釋:Whether to plot on the secondary y-axis If a list/tuple, which columns to plot on secondary y-axis
關於pandas中plot命令總結可以參照這篇文章:https://blog.csdn.net/u013084616/article/details/79064408
