python条形图和折线图与pandas& matplotlib [英] python bar graph and line graph in same chart with pandas & matplotlib

查看:102
本文介绍了python条形图和折线图与pandas& matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大熊猫数据框中,我有每日库存量[bar]和同一天[line]的65天移动平均线.我希望它们彼此重叠,但无法弄清楚该怎么做.有人可以告诉我吗?

in a pandas dataframe I have daily stock volume [bar] and a 65 day moving average of the same [line]. I would like them overlayed on one another but cannot figure out how to do it. Can someone please show me?

谢谢

推荐答案

这是一种解决方法

随机数据

rng = pd.date_range('1/1/2011', periods=100, freq='D')
ts = pd.Series(np.random.randn(len(rng)), index=rng).cumsum()

Barchart具有10天移动平均线.

Barchart with 10-day moving average line.

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

这篇关于python条形图和折线图与pandas& matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆