Is there a way to pass different vertical lines to each subplot when using pandas histogram with “by=somevar”?

蓝咒 提交于 2019-12-25 02:27:05

问题


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

For example if I do:

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

I get

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.

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.


回答1:


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

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



来源:https://stackoverflow.com/questions/24917580/is-there-a-way-to-pass-different-vertical-lines-to-each-subplot-when-using-panda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!