Python 3.x python条形图和折线图与pandas&;matplotlib

Python 3.x python条形图和折线图与pandas&;matplotlib,python-3.x,pandas,matplotlib,Python 3.x,Pandas,Matplotlib,在熊猫数据框中,我有每日库存量[bar]和同一[line]的65天移动平均值。我希望它们彼此重叠,但不知道怎么做。谁能给我看看吗 谢谢这里有一个方法 随机数据 rng = pd.date_range('1/1/2011', periods=100, freq='D') ts = pd.Series(np.random.randn(len(rng)), index=rng).cumsum() 带有10天移动平均线的条形图 fig = plt.figure() ax = ts.plot(kind=

在熊猫数据框中,我有每日库存量[bar]和同一[line]的65天移动平均值。我希望它们彼此重叠,但不知道怎么做。谁能给我看看吗


谢谢这里有一个方法

随机数据

rng = pd.date_range('1/1/2011', periods=100, freq='D')
ts = pd.Series(np.random.randn(len(rng)), index=rng).cumsum()
带有10天移动平均线的条形图

fig = plt.figure()
ax = ts.plot(kind="bar")   # barchart
ax2 = ax.twinx()
ax2.plot(ax.get_xticks(), pd.rolling_mean(ts, 10)) #linechart

谢谢。但是,如果垂直条,移动平均线的峰值怎么可能超过峰值呢?这个代码不起作用。ax2.plot(ax.get_xticks()、ts.rolling(10.mean())工作正常。