Sunday, 24 September 2017

How to create histogram ?


Histogram : Graphical representation of the distribution of numerical data
It is used to understand how data is distributed across the bins.

Normal distribution : Arrangement of data set where most values cluster in the middle of the range and rest towards either extreme.
Its graphical representation is called BELL CURVE.
Mean, mode and median are all the same.

Normalized histogram : Histogram having Normal distribution.

USE matplotlib TO PLOT THE HISTOGRAM (CHART)

EXAMPLE 1
import matplotlib.pyplot as plt 
# Plot the histogram with fixed data

plt.hist([1, 2, 1], bins=[0, 1, 2, 3])
plt.show()


EXAMPLE 2
import matplotlib.pyplot as plt
import numpy as np
 

# Generate items with 1000 items
x = np.random.normal(size = 1000)

# Plot the histogram
plt.hist(x, normed=True, bins=30)
plt.ylabel('Probability') 
plt.show()


EXAMPLE 3
import matplotlib.pyplot as plt
import numpy as np
 

# Generate items with 1000 items
x = np.random.normal(size = 1000)

# Cumulative histogram 1 
plt.hist(x,
         bins=100,
         normed=True,
         stacked=True,
         cumulative=True
)
plt.show()
 
# Cumulative histogram 2
plt.hist(x,
         bins=100,
         normed=True,
         stacked=True,
        
)
plt.show()

No comments:

Post a Comment

Note: only a member of this blog may post a comment.