欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

画出沪深300指数曲线

发布时间:2025/4/5 编程问答 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 画出沪深300指数曲线 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

画出沪深300指数曲线

#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Jan 31 18:30:41 2019@author: lg """ import tushare as ts #获取连接备用 cons = ts.get_apis() ts.set_token('luoganttcc46fcca1e059c38cde5f56fe7748f53c274036cb8cf0c061c2056a690') pro = ts.pro_api()from matplotlib import pyplot as plt import matplotlib.dates as mdatedf = ts.bar('000300', conn=cons, asset='INDEX', start_date='2018-01-01', end_date='2018-12-31') df=df.sort_index()import pandas as pd #生成figure对象 fig = plt.figure(figsize=(12,6)) #生成axis对象#plt.figure(figsize=(8,6)) ax = fig.add_subplot(111) #本案例的figure中只包含一个图表 #设置x轴为时间格式,这句非常重要,否则x轴显示的将是类似于‘736268’这样的转码后的数字格式 ax.xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d'))#设置x轴坐标值和标签旋转45°的显示方式 plt.xticks(pd.date_range(df.index[0],df.index[-1],freq='M'),rotation=45) #x轴为table.index,也就是‘受理日期’,y轴为数量,颜色设置为红色 ax.plot(df.index,df['open'],color='b') plt.show()

posted on 2019-02-05 12:19 luoganttcc 阅读(...) 评论(...) 编辑 收藏

总结

以上是生活随笔为你收集整理的画出沪深300指数曲线的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。