画出沪深300指数曲线
生活随笔
收集整理的這篇文章主要介紹了
画出沪深300指数曲线
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
畫出滬深300指數(shù)曲線
#!/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中只包含一個(gè)圖表 #設(shè)置x軸為時(shí)間格式,這句非常重要,否則x軸顯示的將是類似于‘736268’這樣的轉(zhuǎn)碼后的數(shù)字格式 ax.xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d'))#設(shè)置x軸坐標(biāo)值和標(biāo)簽旋轉(zhuǎn)45°的顯示方式 plt.xticks(pd.date_range(df.index[0],df.index[-1],freq='M'),rotation=45) #x軸為table.index,也就是‘受理日期’,y軸為數(shù)量,顏色設(shè)置為紅色 ax.plot(df.index,df['open'],color='b') plt.show()posted on 2019-02-05 12:19 luoganttcc 閱讀(...) 評論(...) 編輯 收藏
總結(jié)
以上是生活随笔為你收集整理的画出沪深300指数曲线的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pytho sin(1/x)震荡间断点
- 下一篇: 世界层级划分