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:
我需要使用一些股票数据制作烛台图表(类似这样)。为此,我想使用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)]
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.
我现在也需要一个Axes实例,我有点迷失了。我在使用matplotlib.pyplot之前创建了图。我想我现在需要用matplotlib.axes做一些事情,但我不确定到底是什么。
Could anybody help me out a little bit here? All tips are welcome!
有人可以帮我一点吗?欢迎所有提示!
2 个解决方案
#1
69
Use the gca
("get current axes") helper function:
使用gca(“获取当前轴”)辅助函数:
ax = plt.gca()
Example:
例:
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()
#2
7
You can either
你也可以
fig, ax = plt.subplots() #create figure and axes
candlestick(ax, quotes, ...)
or
要么
candlestick(plt.gca(), quotes) #get the axis when calling the function
The first gives you more flexibility. The second is much easier if candlestick is the only thing you want to plot
第一个为您提供更大的灵活性。如果烛台是你想要绘制的唯一东西,第二个就容易多了
#1
69
Use the gca
("get current axes") helper function:
使用gca(“获取当前轴”)辅助函数:
ax = plt.gca()
Example:
例:
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()
#2
7
You can either
你也可以
fig, ax = plt.subplots() #create figure and axes
candlestick(ax, quotes, ...)
or
要么
candlestick(plt.gca(), quotes) #get the axis when calling the function
The first gives you more flexibility. The second is much easier if candlestick is the only thing you want to plot
第一个为您提供更大的灵活性。如果烛台是你想要绘制的唯一东西,第二个就容易多了