user28474
0
Q:

histogram python

import numpy as np
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
x = [21,22,23,4,5,6,77,8,9,10,31,32,33,34,35,36,37,18,49,50,100]
num_bins = 5
n, bins, patches = plt.hist(x, num_bins, facecolor='blue', alpha=0.5)
plt.show()
2
from matplotlib import pyplot as plt 
import numpy as np 
  
  
# Creating dataset 
a = np.array([22, 87, 5, 43, 56,  
              73, 55, 54, 11, 
              20, 51, 5, 79, 31, 
              27]) 
  
# Creating histogram 
fig, ax = plt.subplots(figsize =(10, 7)) 
ax.hist(a, bins = [0, 25, 50, 75, 100]) 
  
# Show plot 
plt.show() 
0
import matplotlib.pyplot as plt
 
x = [1,1,2,3,3,5,7,8,9,10,
     10,11,11,13,13,15,16,17,18,18,
     18,19,20,21,21,23,24,24,25,25,
     25,25,26,26,26,27,27,27,27,27,
     29,30,30,31,33,34,34,34,35,36,
     36,37,37,38,38,39,40,41,41,42,
     43,44,45,45,46,47,48,48,49,50,
     51,52,53,54,55,55,56,57,58,60,
     61,63,64,65,66,68,70,71,72,74,
     75,77,81,83,84,87,89,90,90,91
     ]

plt.hist(x, bins=10)
plt.show()
0
kwargs2 = dict(histtype='step')
fig, ax1=plt.subplots(1,1,sharey=True, facecolor='w',figsize=(8,6))

counts_zi, bins_zi = np.histogram(np.array(dt_mu_zi)*60)
ax1.hist(bins_zi[:-1], bins_zi, weights=100*counts_zi/counts_zi.sum(),color='red', **kwargs2)

x0, x1 = ax1.get_xlim()
ax1.set_xlim([x0,x0+1*(x1-x0)])

ax1.set_ylabel('Frequency',fontsize=12)
ax1.set_xlabel('Delta time (minutes)',fontsize=12)
plt.xticks([-180,-150,-120,-90,-60,-30,0,30,60,90,120,150,180])
0
>>> np.histogram([1, 2, 1], bins=[0, 1, 2, 3])
(array([0, 2, 1]), array([0, 1, 2, 3]))
>>> np.histogram(np.arange(4), bins=np.arange(5), density=True)
(array([0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4]))
>>> np.histogram([[1, 2, 1], [1, 0, 1]], bins=[0,1,2,3])
(array([1, 4, 1]), array([0, 1, 2, 3]))
0

New to Communities?

Join the community