从tushare获取数据 用mplfinance库绘制k线图
python代码如下
import tushare as ts import pandas as pd import mplfinance as mpf df = ts.get_hist_data('300783') df.to_excel('d:/300783.xlsx') df1=pd.read_excel('d:/300783.xlsx') cols=['date','open','high','low','close','volume'] df2 = df1[cols] df3=df2.set_index('date') df3.index=pd.DatetimeIndex(df3.index) df3=df3.sort_values(by='date') mpf.plot(df3,type='candle',datetime_format='%Y-%m-%d',figratio=(30,6 ),style='yahoo')
三只松鼠历史k线图: