Home » Python » Python programs

Histogram using Pylab in Python

Here, we are going to learn how to print histogram using Pylab in Python?
Submitted by Anuj Singh, on June 24, 2019

A histogram is a plot which shows the distribution of values in a set of data. The values are sorted first and then divided into classes/group of equal size.

So, in this article, we are going to use hist() function to plot the histogram of the sum of randomly generated numbers.

The function pylab.hist(vals, bin = 10) produces a histogram with 10 equally sized groups and the frequency of result in those classes.

So here is the code:

import random
import pylab
val = []

for n in range(1004):
    x = random.choice(range(0,90))
    y = random.choice(range(0,90))
    val.append(x+y)
    
pylab.hist(val, bins = 10)
pylab.xlabel('NUMBER OF OCCURENCE')    

Output:

histogram in Python







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.