pandas 多个地块不能作为历史

编程入门 行业动态 更新时间:2024-10-28 15:27:24
本文介绍了 pandas 多个地块不能作为历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Pandas中使用数据框df,我试图在同一页面上绘制直方图,并通过3个不同的变量进行过滤;预期的结果是三种类型中每种类型的值的直方图.以下代码对我来说很适合PLOT,但是当我改用HIST时,它们全部相互叠加.有什么建议?

with a dataframe df in Pandas, I am trying to plot histograms on the same page filtering by 3 different variables; the intended outcome is histograms of the values for each of the three types. The following code works for me as PLOTs, but when I change to HISTs, they all stack on top of each other. Any suggestions?

plt.figure(1) plt.subplot(311) df[df.Type == 'Type1'].values.plot() plt.subplot(312) df[df.Type == 'Type2'].values.plot() plt.subplot(313) df[df.Type == 'Type3'].values.plot() plt.savefig('output.pdf')

这是熊猫中的错误,还是情节和历史不能互换?

Is this a bug in Pandas or are plot and hist not interchangable?

预先感谢

推荐答案

图和hist不能互换:hist是它自己的 DataFrame 和 Series 方法.您可以通过传入ax关键字来强制绘图独立.所以

Plot and hist aren't interchangabe: hist is its own DataFrame and Series methods. You might be able to force the plots to be independent by passing in an ax keyword. So

fig = plt.figure() ax1 = fig.add_subplot(3,1,1) df[df.Type == 'Type1'].values.hist(ax=ax1) ....

更多推荐

pandas 多个地块不能作为历史

本文发布于:2023-07-19 16:59:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1158542.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   地块   历史   pandas

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!