目前市场上展示股票走势最常见的就是日K图,日K图可以展示个股多天的数据,每一天展示的数据包括开盘价、收盘价、最高价、最低价。如果收盘价大于开盘价,则当天是一个红柱图,否则是一个绿柱图。
Python绘制日K图有现成的函数可以调用,mpl_finance提供了绘制日K的函数,我们主要调用的是candlestick2_ochl函数,其定义如下:
def candlestick2_ochl(ax, opens, closes, highs, lows, width=4,
colorup='k', colordown='r',
alpha=0.75):
"""Represent the open, close as a bar line and high low range as a
vertical line.
Preserves the original argument order.
Parameters
----------
ax : `Axes`
an Axes instance to plot to
opens : sequence
sequence of opening values
closes : sequence
sequence of closing values
highs : sequence
sequence of high values
lows : sequence
sequence of low values
width : int
size of open and close ticks in points
colorup : c