Skip to content
Advertisement

How to combine 2 dataframe histograms in 1 plot?

I would like to use a code that shows all histograms in a dataframe. That will be df.hist(bins=10). However, I would like to add another histograms which shows CDF df_hist=df.hist(cumulative=True,bins=100,density=1,histtype="step")

I tried separating their matplotlib axes by using fig=plt.figure() and plt.subplot(211). But this df.hist is actually part of pandas function, not matplotlib function. I also tried setting axes and adding ax=ax1 and ax2 options to each histogram but it didn’t work.

How can I combine these histograms together? Any help?

Histograms that I want to combine are like these. I want to show them side by side or put the second one on tip of the first one. Sorry that I didn’t care to make them look good. histogram1 histogram2

Advertisement

Answer

It is possible to draw them together:

JavaScript

Output:

enter image description here

It’s also possible to draw them side-by-side. For example

JavaScript

will plot hist on top of kde.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement