from matplotlib import pyplot as plt
y1 = [1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
y2 = [1,0,3,1,2,2,3,3,2,1,2,1,1,1,1,1,1,1,1,1]
x = range(11,31)
plt.figure(figsize=(20,8),dpi=80)
#画图
plt.plot(x,y1,label='self',color='#db7893',linestyle='--',linewidth=5)
plt.plot(x,y2,label='tong',color='cyan',linestyle=':',linewidth=5,alpha=0.5)
#标注
plt.annotate('local max', xy=(22, 6), xytext=(20, 6),arrowprops=dict(facecolor='black', shrink=0.05))
plt.text(23, 6, "(23,6)", ha='center', rotation=0, wrap=True)
#刻度
_xticks_labels = ['{}岁'.format(i) for i in x]
plt.xticks(x,_xticks_labels,rotation=45)
plt.yticks(range(0,9))
plt.grid(alpha=0.5,linestyle=':')
#标题
plt.xlabel('age')
plt.ylabel('number')
plt.title('friends')
#图例
plt.legend(loc='lower left')
#保存
plt.savefig('./sig_size.png')
plt.show()
from matplotlib import pyplot as plt
#设置图片尺寸
plt.figure(figsize=(20,8),dpi=80)
x = range(2,27,2)
y = [15,13,14,5,17,20,25,26,26,27,22,18,15]
#设置更细刻度
_xticks_labels = [i/2 for i in range(4,49)]
#plt.xticks(range(25,50))
plt.xticks(x,_xticks_labels)
plt.yticks(range(min(y),max(y)+1))
plt.plot(x,y)
x = range(0,120)
y = [random.randint(20,35) for i in range(120)]
_x = list(x)
#显示刻度中文
_xtick_labels = ['10点{}分'.format(i) for i in range(60)]
_xtick_labels += ['11点{}分'.format(i) for i in range(60)]
plt.xticks(_x[::3],_xtick_labels[::3],rotation=45)
plt.plot(x,y)