题目说的好像和股票有关,实际上就是一个时间序列图。但本节主要介绍时间序列的几个常用统计方法。详细如下:
1、 画出股票(代码:688022)的收盘价趋势图
【脚本】
import tushare as ts
import matplotlib.pyplot as plt
frame = ts.get_k_data('688022', start='2019-07-22')
frame = frame.set_index('date')
frame.index = pd.to_datetime(frame.index)
plt.plot(frame['close'])
plt.show()
【结果】
【说明】
Python有很多可视化绘图工具包,我们使用常用的matplotlib. 使用之前需要导入。
Plt.figure()可以设置画布的大小和分辨率。我使用pycharm工具,没有设置画布信息,也可以使用正常画出图片。
Plt.plot(),设置绘图内容。
Plt.show(),显示绘图。
我们可看出该股票总体呈现出一种下降趋势。
2、 平滑法——移动平均法
【脚本】
plt.plot(frame['close'].rolling(30).mean())
plt.show()
【结果】
【说明】
平