最新版mplfinance画股市蜡烛图

记录下用python画蜡烛图

import tushare as ts
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import mplfinance as mpf
import numpy as np
from datetime import datetime

ts.set_token('your token')
pro = ts.pro_api()
df = pro.daily(ts_code='000001.SZ', start_date='20180701', end_date='20180718')
df['date'] = df['trade_date'].apply(lambda x: datetime.strptime(x, '%Y%m%d'))
data = df.loc[:,['date', 'open','close','high','low','vol']]
data = data.rename(columns={"vol": "volume"})
data.set_index('date', inplace=True)
data.index.name = "Date"
data.index = pd.DatetimeIndex(data.index)
data=data.reindex(index=data.index[::-1])

# data.head
mc = mpf.make_marketcolors(up='r',down='g')
s  = mpf.make_mpf_style(marketcolors=mc,mavcolors=['#4f8a8b','#fbd46d','#87556f'])

mpf.plot(data,type='candle',volume=True, show_nontrading=True, figratio=(20,10), mav=(5,10,15),style=s)

最新版mplfinance画股市蜡烛图_第1张图片

如何获取数据:

https://tushare.pro/register?reg=332190

画图:

https://github.com/matplotlib/mplfinance

https://github.com/matplotlib/mplfinance/blob/master/examples/styles.ipynb

你可能感兴趣的:(Python)