/**/ Python & MySQL: PLOTTING WITH PYPLOT II – HISTOGRAM, FREQUENCY DISTRIBUTION, BOXPLOTS (PART - 2) CLASS - XII

Monday, June 29, 2020

PLOTTING WITH PYPLOT II – HISTOGRAM, FREQUENCY DISTRIBUTION, BOXPLOTS (PART - 2) CLASS - XII

PLOTTING WITH PYPLOT II – HISTOGRAM, FREQUENCY DISTRIBUTION, BOXPLOTS

Chapter – 4 (SECOND PART)

Class – XII

Another example of Histogram:

Look at the following example that plot histogram from two ndarrays x and y each having randomly generated some numbers.

1. Plot a histogram from an ndarray x with 7 bins

import numpy as np

import matplotlib.pyplot as plt

x = np.random.normal(-1,1,100)

y = np.random.normal(-1,1,100)

#print(x)

plt.hist(x, bins = 7)

plt.show()

 



2. Plot a histogram from an ndarray y with 5 bins

import numpy as np

import matplotlib.pyplot as plt

x = np.random.normal(-1,1,100)

y = np.random.normal(-1,1,100)

#print(x)

plt.hist(y, bins = 5)

plt.show()

 


3. Plot a cumulative histogram of ndarray x with 20 bins

import numpy as np

import matplotlib.pyplot as plt

x = np.random.normal(-1,1,100)

y = np.random.normal(-1,1,100)

#print(x)

plt.hist(x, bins = 20, cumulative = True)

plt.show()

 


4. Plot ndarray x’s histogram as ‘step’ type histogram with 9 bins

import numpy as np

import matplotlib.pyplot as plt

x = np.random.normal(-1,1,100)

y = np.random.normal(-1,1,100)

plt.hist(x, bins = 9, histtype = 'step')

plt.show()

 

 


5. Plot both ndarray x and y in same histogram

import numpy as np

import matplotlib.pyplot as plt

x = np.random.normal(-1,1,100)

y = np.random.normal(-1,1,100)

plt.hist([x,y])

plt.show()

 



6. Plot a stacked bar type histogram from both ndarray x and y

(a) regular histogram

import numpy as np

import matplotlib.pyplot as plt

x = np.random.normal(-1,1,100)

y = np.random.normal(-1,1,100)

plt.hist([x,y], histtype = 'barstacked')

plt.show()

 

(b) Cumulative histogram

import numpy as np

import matplotlib.pyplot as plt

x = np.random.normal(-1,1,100)

y = np.random.normal(-1,1,100)

plt.hist([x,y], histtype = 'barstacked', cumulative = True)

plt.show()

 

 


7. Plot a horizontal histogram from ndarray y with 20 bins

import numpy as np

import matplotlib.pyplot as plt

x = np.random.normal(-1,1,100)

y = np.random.normal(-1,1,100)

plt.hist(y,bins = 20, orientation = 'horizontal')

plt.show()

 


Creating Frequency Polygons:

A frequency polygon is a type of frequency distribution graph. In a frequency polygon, the number of observations is marked with a single point at the midpoint of an interval. A straight line then connects each set of points. Frequency polygons make it easy to compare two or more distributions on the same set of axes.


NOTE: This is the notes of Chapter - IV Plotting with Pyplot - II  - Histogram, Frequency, BoxPlots. It is important for every students, who are going to appear in Class - XII CBSE BOARD Exam as well as competitive level exam.

THANK YOU !!!












No comments:

Post a Comment

Please do not any spam in the comment box.

CLASS XI HALF YEARLY QP WTH MS 2024

  Half Yearly Examination: 2024-25 Informatics Practices (065) Class- XI       Time Allowed: 3hrs                                     ...