需求分解
- 使用wind 提供的python API接口查询某支股票的收盘价
- 使用matplotlib对收盘价进行图形展示
- 利用python word相关包生成word格式报告
part1:使用使用wind 提供的python API接口查询某支股票的收盘价
| w.start() |
| |
| codes = ['300750.SZ','000300.SH'] |
| fields = ['close'] |
| beginTime = '2021-01-01' |
| endTime = '2022-05-21' |
| stockInfo = w.wsd(codes,fields,beginTime,endTime,usedf=True)[1] |
| stockInfo = stockInfo.reset_index() |
| stockInfo.columns = ['日期','宁德时代','沪深300指数'] |
part2:使用matplotlib对收盘价进行图形展示
| |
| |
| plt.rcParams["font.sans-serif"]=["SimHei"] |
| |
| plt.rcParams["axes.unicode_minus"]=False |
| stockData = stockInfo['日期'] |
| stockClose = stockInfo['宁德时代'] |
| stockIndex = stockInfo['沪深300指数'] |
| fig = plt.figure() |
| |
| ax = fig.add_axes([0,0,1,1]) |
| ax.plot(stockData,stockClose,'b-') |
| ax.set_title('宁德时代股价波动趋势') |
| ax.grid(True) |
| ax1 = ax.twinx() |
| ax1.plot(stockData,stockIndex,'r-') |
| ax1.set_ylabel('沪深300指数') |
| |
| |
| ax.set_xlabel('日期') |
| ax.set_ylabel('宁德时代收盘价') |
| plt.savefig('my.png',dpi=200,bbox_inches = 'tight' ) |
| plt.show() |

part3:利用python word相关包生成word格式报告
未完待续。。
遇到的问题
- matplotlib导出的图形没有标题和坐标轴
参考1:https://blog.csdn.net/weixin_42279212/article/details/120665026
参考2:在保存时增加 bbox_inches = 'tight'参数
| fig.savefig('my.png',dpi=200,bbox_inches = 'tight') |
- savefig()函数的具体参数
参考:https://blog.csdn.net/m0_47384542/article/details/110356507
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)