图形中添加注释

 

数据和内容是《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

 

posted @ 2018-10-11 10:57  平淡才是真~~  阅读(1367)  评论(0编辑  收藏  举报