plt.xticks(x, [
‘2022-03-27’, ‘2022-03-28’, ‘2022-03-29’, ‘2022-03-30’,
‘2022-03-31’, ‘2022-04-01’, ‘2022-04-04’, ‘2022-04-05’,
‘2022-04-06’], rotation=45)
plt.title(‘某股票收盘价时序图’)
plt.xlabel(‘日期’)
plt.ylabel(‘价格’)
plt.grid(True)
plt.legend()
标出每天的收盘价
for a, b in zip(x, y):
plt.text(a, b+0.01, ‘%.1f’%b, ha=‘center’, va=‘bottom’, fontsize=9)
plt.show()
=============================================================================================
在上例代码的基础之上,添加注释。注释即对图像中某一位置的解释,可以用箭头来指向。
添加注释使用的是plt.annotate()方法
其语法中的常用参数如下
plt.annotate(str,xy,xytext,xycoords,arrowcoords)
其中str即注释要使用的字符串,即注释文本
xy指被注释的坐标点
xytext指注释文本要写在的位置
xycoords是被注释的点的坐标系属性,即以什么样的方式描述该点的坐标。设置值默认为"data",即用(x,y)坐标来描述。其他可以选择的设置值如下,其中fi