2

With the following code I create four histograms:

import numpy as np
import pandas as pd

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

enter image description here

I want the histograms to look like this:

enter image description here

I know how to make it one graph at the time, see here

But how can I do it for multiple histograms without specifying each single one? Ideally I could use 'pd.scatter_matrix'.

Community
  • 1
  • 1
cJc
  • 813
  • 1
  • 11
  • 33

1 Answers1

0

Plot each histogram seperately and do the fit to each histogram as in the example you linked or take a look at the hist api example here. Essentially what should be done is

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
fig = plt.figure()
ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(222)
ax3 = fig.add_subplot(223)
ax4 = fig.add_subplot(224)
for ax in [ax1, ax2, ax3, ax4]:
    n, bins, patches = ax.hist(**your_data_here**, 50, normed=1, facecolor='green', alpha=0.75)
    bincenters = 0.5*(bins[1:]+bins[:-1])
    y = mlab.normpdf( bincenters, mu, sigma)
    l = ax.plot(bincenters, y, 'r--', linewidth=1)
plt.show()
pathoren
  • 1,634
  • 2
  • 14
  • 22
  • Thanks for your answer. I was wondering if there is a simpler way to do this as in my real program I have a lot of histograms, four was just used for the example.. – cJc Oct 21 '16 at 06:24
  • I ended up making a function to crate the histogram and the normal distribution curve and then using that function in a for-loop. – cJc Oct 22 '16 at 04:23