luoganttcc

画出沪深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 mdate


df = 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()

在这里插入图片描述

分类:

技术点:

相关文章:

  • 2021-08-25
  • 2022-01-02
  • 2021-12-27
  • 2021-07-13
  • 2021-05-19
  • 2021-12-28
猜你喜欢
  • 2022-01-11
  • 2021-04-20
  • 2022-01-17
  • 2022-01-20
  • 2021-12-29
  • 2021-08-24
  • 2021-12-31
相关资源
相似解决方案