数据格式为:
riqi,total1,total2
2019-06-01,62192,627
2019-06-02,546240,546
2019-06-03,6603,6597
2019-06-04,5943,594
2019-06-05,61289,6128
2019-06-06,65090,6500
2019-06-07,52632,526
2019-06-08,44949,47449
2019-06-09,4720,472
2019-06-10,8143,8173
2019-06-11,6382,89712
2019-06-12,61356,656
2019-06-13,6038,6638
2019-06-14,73,700
2019-06-15,52,529
2019-06-16,538,536
2019-06-17,6463,64624
2019-06-18,224,654
2019-06-19,5989,5930
2019-06-20,5989,5930
2019-06-21,6234,623
2019-06-22,663,64062
2019-06-22,497,49736
2019-06-23,4454,445
2019-06-24,5791,573
2019-06-25,5839,539
2019-06-26,186,59
2019-06-27,6209,629
2019-06-28,9654,964
2019-06-29,500,500
2019-06-30,5104,51904
绘图:
import pandas as pd
import numpy as np
from pandas import Series,DataFrame
import matplotlib.pyplot as plt
from pylab import mpl #设置plt可以显示中文
mpl.rcParams['font.sans-serif'] = ['FangSong']
mpl.rcParams['axes.unicode_minus'] = False
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
shuju = pd.read_csv("wenjian")
def x(r1,r2):
return list(range(r1, r2 + 1))
r1, r2 = 1,30
x = list(x(r1,r2))
y = shuju['total1']
plt.plot(x,y,marker='o')
for xy in zip(x,y):
plt.annotate('local max', xy=(19,5989), xytext=(20,6000), arrowprops=dict(facecolor='black', shrink=0.001,width=0.001))#将指定数据设置标签
plt.annotate("(%s,%s)" % xy, xy=xy, xytext=(-20, 10), textcoords='offset points') #所有数据设置标签
plt.show()
annotate语法说明 :annotate(s='str' ,xy=(x,y) ,xytext=(l1,l2) ,..)
s 为注释文本内容
xy 为被注释的坐标点
xytext 为注释文字的坐标位置
xycoords 参数如下:
- figure points points from the lower left of the figure 点在图左下方
- figure pixels pixels from the lower left of the figure 图左下角的像素
- figure fraction fraction of figure from lower left 左下角数字部分
- axes points points from lower left corner of axes 从左下角点的坐标
- axes pixels pixels from lower left corner of axes 从左下角的像素坐标
- axes fraction fraction of axes from lower left 左下角部分
- data use the coordinate system of the object being annotated(default) 使用的坐标系统被注释的对象(默认)
- polar(theta,r) if not native ‘data’ coordinates t
extcoords 设置注释文字偏移量
arrowprops #箭头参数,参数类型为字典dict
- width the width of the arrow in points 点箭头的宽度
- headwidth the width of the base of the arrow head in points 在点的箭头底座的宽度
- headlength the length of the arrow head in points 点箭头的长度
- shrink fraction of total length to ‘shrink’ from both ends 总长度为分数“缩水”从两端
- facecolor 箭头颜色
bbox给标题增加外框 ,常用参数如下:
- boxstyle方框外形
- facecolor(简写fc)背景颜色
- edgecolor(简写ec)边框线条颜色
- edgewidth边框线条大小
bbox=dict(boxstyle='round,pad=0.5', fc='yellow', ec='k',lw=1 ,alpha=0.5) #fc为facecolor,ec为edgecolor,lw为lineweight