如何绘制matplotlib Axes实例?

kra*_*r65 58 python finance axes matplotlib

我需要使用一些股票数据制作烛台图表(类似这样).为此,我想使用matplotlib.finance.candlestick()函数.对于这个函数,我需要提供引号和" 一个Axes实例来绘制 ".我创建了一些示例引号,如下所示:

quotes = [(1, 5, 6, 7, 4), (2, 6, 9, 9, 6), (3, 9, 8, 10, 8), (4, 8, 8, 9, 8), (5, 8, 11, 13, 7)]
Run Code Online (Sandbox Code Playgroud)

我现在还需要一个Axes实例,我有点迷失了.我在使用matplotlib.pyplot之前创建了图.我想我现在需要用matplotlib.axes做些什么,但我不确定到底是什么.

有人可以帮我一点吗?欢迎所有提示!

wim*_*wim 118

使用gca("获取当前轴")辅助函数:

ax = plt.gca()
Run Code Online (Sandbox Code Playgroud)

例:

import matplotlib.pyplot as plt
import matplotlib.finance
quotes = [(1, 5, 6, 7, 4), (2, 6, 9, 9, 6), (3, 9, 8, 10, 8), (4, 8, 8, 9, 8), (5, 8, 11, 13, 7)]
ax = plt.gca()
h = matplotlib.finance.candlestick(ax, quotes)
plt.show()
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Fra*_*ano 10

你也可以

fig, ax = plt.subplots()  #create figure and axes
candlestick(ax, quotes, ...)
Run Code Online (Sandbox Code Playgroud)

要么

candlestick(plt.gca(), quotes) #get the axis when calling the function
Run Code Online (Sandbox Code Playgroud)

第一个为您提供更大的灵活性.如果烛台是您想要绘制的唯一内容,则第二个更容易