如何获得要绘制的matplotlib Axes实例? [英] How to get a matplotlib Axes instance to plot to?
问题描述
我需要使用一些库存数据制作烛台图(类似这样).为此,我想使用功能 matplotlib.finance.candlestick().为此功能,我需要提供引号和"要绘制到的轴实例".我创建了一些示例报价,如下所示:
I need to make a candlestick chart (something like this) using some stock data. For this I want to use the function matplotlib.finance.candlestick(). To this function I need to supply quotes and "an Axes instance to plot to". I created some sample quotes as follows:
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)]
我现在还需要一个Axes实例,在这个实例上我有点迷茫.我在使用matplotlib.pyplot之前创建了图.我想我现在需要对 matplotlib.axes 做些事情,但是我不确定到底是什么.
I now also need an Axes instance though, at which I am a bit lost. I created plots before using matplotlib.pyplot. I think I now need to do something with matplotlib.axes though, but I am unsure what exactly.
有人可以帮我一下吗?欢迎所有提示!
Could anybody help me out a little bit here? All tips are welcome!
推荐答案
Use the gca
("get current axes") helper function:
ax = plt.gca()
示例:
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()
这篇关于如何获得要绘制的matplotlib Axes实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!