我试图在多个窗口中绘制烛台图表。在通常的折线图中,我可以使用plt.figure()
,plt.plot()
,然后使用plt.show()
。但这对烛台不起作用。任何人都可以帮忙解决这个问题吗?
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick_ohlc
num,op,hi,lo,cl= np.loadtxt('AUDUSDdaily3.csv',
unpack=True,
delimiter=',')
ax1=plt.subplot2grid((1,1),(0,0))
x=0
y=len(num)
ohlc=[]
while x<y:
d1=num[x],op[x],hi[x],lo[x],cl[x]
ohlc.append(d1)
x+=1
plt.figure(1)
candlestick_ohlc(ax1,ohlc[0:50],width=0.4)
plt.figure(2)
candlestick_ohlc(ax1,ohlc[150:200],width=0.4)
plt.show()
答案 0 :(得分:0)
candlestick_ohlc
的第一个参数是要绘制的轴。如果为两个烛台功能提供相同的轴ax1
,它们将出现在相同的轴上。
因此请删除ax1
定义。然后
plt.figure(1)
candlestick_ohlc(plt.gca(),ohlc[0:50],width=0.4)
plt.figure(2)
candlestick_ohlc(plt.gca(),ohlc[150:200],width=0.4)
其中gca()
让你当前的活动轴工作正常。或者,手动定义轴。
fig, ax = plt.subplots()
candlestick_ohlc(ax,ohlc[0:50],width=0.4)
fig2, ax2 = plt.subplots()
candlestick_ohlc(ax2,ohlc[150:200],width=0.4)