画蜡烛线
pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
from mpl_finance import candlestick_ochl
import matplotlib.pyplot as plt
from matplotlib.pylab import date2num# 先画日K线
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(20, 8), dpi=80)
# 准备数据, array数组
stock_day['date'] = date2num(stock_day.index)
day_k = stock_day[['date', 'open', 'close', 'high', 'low']]
# 绘制k线图
candlestick_ochl(axes, day_k.values, width=0.2, colorup='r', colordown='g')
# x刻度设置为日期
axes.xaxis_date()
plt.show()# 周K线图数据显示出来
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(20, 8), dpi=80)
period_week_data['date'] = date2num(period_week_data.index)
week_k = period_week_data[['date', 'open', 'close', 'high', 'low']]
# 绘制k线图
candlestick_ochl(axes, week_k.values, width=0.2, colorup='r', colordown='g')
# x刻度设置为日期
axes.xaxis_date()
plt.show()
# 拿到股票K线数据
stock_day = pd.read_csv("./stock_day/stock_day.csv")
stock_day = stock_day.sort_index()
stock_day.index = pd.to_datetime(stock_day.index)
stock_day['date'] = date2num(stock_day.index)
arr = stock_day[['date', 'open', 'close', 'high', 'low']]
values = arr.values[:200]
# 画出K线图
fig, axes = plt.subplots(nrows=1, ncols=1, figsize=(20, 8), dpi=80)
candlestick_ochl(axes, values, width=0.2, colorup='r', colordown='g')
axes.xaxis_date()
plt.show()