使用带有"by = somevar"的 pandas 直方图时,有没有办法将不同的垂直线传递到每个子图? [英] Is there a way to pass different vertical lines to each subplot when using pandas histogram with "by=somevar"?

查看:63
本文介绍了使用带有"by = somevar"的 pandas 直方图时,有没有办法将不同的垂直线传递到每个子图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用熊猫制作直方图,我发现这种方法很方便.

I'm making histograms using pandas and I find this approach convenient.

例如,如果我这样做:

df ['plotvar'].hist(by ='Zone')

df['plotvar'].hist(by='Zone')

我知道

但是,现在我想在每个子组上添加95%CI,当然每个组的间隔是不同的.我可以只使用matplotlib中的plt.axvline来做到这一点,但是不确定使用熊猫制作原始地块时该如何做.任何输入/建议的TIA.

But now I want to add the 95%CI on each of these subgroups, and of course the intervals are different for each group. I could do it just using plt.axvline in matplotlib, but not sure how to do it when I've made the original plots using pandas. TIA for any inputs/suggestions.

我要补充一点,我已经知道95%CI值是多少.这只是一个绘图问题(如何将axvline应用于这些子图中的每一个).谢谢.

edit: I shoudl add that I already know what the 95%CI values are. This is just a plotting question (how to apply the axvline to each of these subplots). Thx.

推荐答案

DataFrame.hist()by=一起返回matplotlib轴的数组,因此您可以抓住它,然后对其进行迭代.

DataFrame.hist() with by= returns the array of matplotlib Axes, so you could grab that and then iterate over it.

对于可以说熊猫但具有更灵活功能的类似功能,您可以使用来自 seaborn 的FacetGrid 对象.

For similar functionality that speaks pandas but has more flexible features you could use the FacetGrid object from seaborn.

这篇关于使用带有"by = somevar"的 pandas 直方图时,有没有办法将不同的垂直线传递到每个子图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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