Plotting histograms in Python using pandas

放肆的年华 提交于 2020-02-23 06:58:31

问题


I'm trying to create a histogram with two data sets overlying each other, however whenever I plot it using pandas.DataFrame.hist(), it creates two graphs:

The code is simply:

ratios.hist(bins = 100)
plt.show()

where ratios is just a DataFrame, 2 columns by about 7000 rows. Any idea on how to put the two graphs on the same axis?


回答1:


Try plot.hist instead:

ratios = pd.DataFrame(np.random.normal((1, 2), size=(100, 2)))
ratios.hist(bins=10)

This generates:

ratios.plot.hist(alpha=0.5, bins=10)

This, on the other hand, puts them on the same graph:



来源:https://stackoverflow.com/questions/39529941/plotting-histograms-in-python-using-pandas

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