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

在这里插入图片描述

转载于:https://www.cnblogs.com/luoganttcc/p/10525219.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值