【发布时间】:2021-11-14 11:46:38
【问题描述】:
我有两个熊猫系列。我需要用彼此堆叠的共享 X 轴来绘制它们。我尝试了下面的代码,但不是将它们堆叠起来,而是将两条线放在同一个图上。这是为什么?如何堆叠它们?
n=10
x = pd.Series(data = np.random.randint(0,10, n), index=pd.date_range(pd.to_datetime('today'), freq='D', periods=n))
y = pd.Series(data = np.random.randint(0,10, n), index=pd.date_range(pd.to_datetime('today'), freq='D', periods=n))
ax = x.plot()
ax2 = y.plot()
ax2.sharex(ax)
我知道可以使用subplots 完成堆叠。如果我理解正确的话,pandas 的唯一句柄是调用df.plot() 时返回的ax。我如何使用这个ax 来实现共享横坐标的正确堆叠?
【问题讨论】:
标签: python pandas matplotlib plot