Histogramas


In [3]:
%pylab inline


Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.

Datos Aleatorios


In [9]:
x = np.random.random(100)
y = np.random.normal(loc = 1.0, size=100)

1D Histogram


In [23]:
hist_x, bin_edges_x = np.histogram(x)
hist_y, bin_edges_y = np.histogram(y)

Y esto?


In [24]:
print hist_x, bin_edges_x
print len(hist_x), len(bin_edges_x)


[16 10 10 13  7  9  9 13  9  4] [ 0.02385132  0.12095332  0.21805532  0.31515732  0.41225932  0.50936132
  0.60646333  0.70356533  0.80066733  0.89776933  0.99487133]
10 11

Graficando


In [26]:
fig = figure(figsize=(9.5, 9))
plt.tick_params(axis='both', which='major', labelsize=15)
plt.plot(bin_edges_x[0:-1], hist_x)


Out[26]:
[<matplotlib.lines.Line2D at 0x487a510>]

In [28]:
fig = figure(figsize=(9.5, 9))
plt.tick_params(axis='both', which='major', labelsize=15)
plt.plot(bin_edges_y[0:-1], hist_y)


Out[28]:
[<matplotlib.lines.Line2D at 0x4bc5d10>]

Mas funciones dentro de hitogram


In [39]:
hist_x, bin_edges_x = np.histogram(x, bins=30, normed=True)
hist_y, bin_edges_y = np.histogram(y, bins=10, normed=True)

In [40]:
fig = figure(figsize=(9.5, 9))
plt.tick_params(axis='both', which='major', labelsize=15)
plt.plot(bin_edges_x[0:-1], hist_x)


Out[40]:
[<matplotlib.lines.Line2D at 0x5d57790>]

In [42]:
fig = figure(figsize=(9.5, 9))
plt.tick_params(axis='both', which='major', labelsize=15)
plt.plot(bin_edges_y[0:-1], hist_y)


Out[42]:
[<matplotlib.lines.Line2D at 0x61a9610>]

In [59]:
hist_x, bin_edges_x, patches = hist(x, bins=30, normed=True, histtype='bar')



In [60]:
hist_y, bin_edges_y, patches = hist(y, bins=30, normed=True, histtype='bar')



In [72]:
fig = figure(figsize=(9.5, 9))
x = np.random.random(10000)
y = np.random.random(10000)
hist2d(x, y, bins = 40)


Out[72]:
(array([[  9.,   9.,   8., ...,   6.,  10.,   6.],
       [  3.,   7.,   7., ...,  11.,   5.,   1.],
       [  6.,   5.,   8., ...,   5.,   5.,  11.],
       ..., 
       [  8.,   5.,   3., ...,   6.,   5.,   8.],
       [  4.,   8.,   8., ...,   5.,   4.,   5.],
       [  7.,   8.,  11., ...,   8.,   5.,   9.]]),
 array([  6.08084353e-06,   2.49970643e-02,   4.99880478e-02,
         7.49790312e-02,   9.99700147e-02,   1.24960998e-01,
         1.49951982e-01,   1.74942965e-01,   1.99933949e-01,
         2.24924932e-01,   2.49915915e-01,   2.74906899e-01,
         2.99897882e-01,   3.24888866e-01,   3.49879849e-01,
         3.74870833e-01,   3.99861816e-01,   4.24852800e-01,
         4.49843783e-01,   4.74834767e-01,   4.99825750e-01,
         5.24816734e-01,   5.49807717e-01,   5.74798700e-01,
         5.99789684e-01,   6.24780667e-01,   6.49771651e-01,
         6.74762634e-01,   6.99753618e-01,   7.24744601e-01,
         7.49735585e-01,   7.74726568e-01,   7.99717552e-01,
         8.24708535e-01,   8.49699519e-01,   8.74690502e-01,
         8.99681486e-01,   9.24672469e-01,   9.49663452e-01,
         9.74654436e-01,   9.99645419e-01]),
 array([  9.50244048e-05,   2.50896845e-02,   5.00843446e-02,
         7.50790047e-02,   1.00073665e-01,   1.25068325e-01,
         1.50062985e-01,   1.75057645e-01,   2.00052305e-01,
         2.25046965e-01,   2.50041625e-01,   2.75036286e-01,
         3.00030946e-01,   3.25025606e-01,   3.50020266e-01,
         3.75014926e-01,   4.00009586e-01,   4.25004246e-01,
         4.49998906e-01,   4.74993566e-01,   4.99988226e-01,
         5.24982887e-01,   5.49977547e-01,   5.74972207e-01,
         5.99966867e-01,   6.24961527e-01,   6.49956187e-01,
         6.74950847e-01,   6.99945507e-01,   7.24940167e-01,
         7.49934827e-01,   7.74929488e-01,   7.99924148e-01,
         8.24918808e-01,   8.49913468e-01,   8.74908128e-01,
         8.99902788e-01,   9.24897448e-01,   9.49892108e-01,
         9.74886768e-01,   9.99881429e-01]),
 <matplotlib.image.AxesImage at 0x7dfb290>)

In [ ]: