'Plot histograms of 2 different dataframes with the same columns

I have 2 dataframes named df1 and df2 with the same 15 columns. Say df1 has columns A, B ,C and df1 has columns A,B,C as well. I want to use .hist() so that I have 15 plots each consisting of 2 histograms one on another(i.e. Plot 1 has histogram of column A from DF1 and column A from df2). I want these 2 dataframe's plots to have the same scale as I tried another way and ended up getting irregular x axes.

   df1 =  A B C
        1 . . .
        2 . . .
        3 . . .
   df2 =  A B C
        1 * * *
        2 * * *
        3 * * *
#Plot 1 should have column A from df1 and column A from df2.
#Plot 1 should have column B from df1 and column B from df2.
# and so on.

[I tried making a single graph code so this was the output.] https://i.stack.imgur.com/w5wSM.png



Solution 1:[1]

Determine the bins that you require:

a = np.linspace(start, stop, nbins)
hist1 = np.histogram(df1.A, bins=a)
hist2 = np.histogram(df2.A, bins=a)

Here 'a' is the sequence that the histogram would use to make the bins

https://numpy.org/doc/stable/reference/generated/numpy.histogram.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonathan Pacheco