Histogram
Histogram
matplotlib.pyplot.hist(x, bins=value,cumulative=False,
histtype=type, align=alignment,
orientation=orientation)
where,
x: It is list to be plotted on histogram
cumulative: It is a boolean value i.e. either True or False. If provided True then
bins are calculated where each bin gives the counts in that bin plus all bins for
smaller values. The last bin gives total number of data points. The default value is
false.
bar: Bar type histogram, it arranges data side by side if given data is multiple. It is
by default histtype.
barstacked: When multiple data are stacked on top of each other
step: Generates a lineplot that is by default unfilled
stepfilled: Generates a lineplot that is by default filled
orientation:horizontal or vertical.
import matplotlib.pyplot as plt
marks= [100,45,69,43,85,79,45,69,45,90,100]
plt.hist(marks)
plt.show()
import matplotlib.pyplot as plt
marks= [100,45,69,43,85,79,45,69,45,90,100]
plt.hist(marks,bins=[0,45,50,70,100])
plt.show()
Range:
0-45
45-50
50-70
70-100
import matplotlib.pyplot as plt
marks= [100,45,69,43,85,79,45,69,45,90,100]
plt.hist(marks,bins=[0,45,50,70,100],rwidth=0.9)
plt.show()
Range:
0-45
45-50
50-70
70-100
bins : can be int or sequence or str, optional (default :10)
bins=[0,45,50,70,100]
Will have 4 bins i.e [0 to 44,45 to 49,50to 69,70 to 100]
4+2=6
1+3=4
1
histtype-
import matplotlib.pyplot as plt
marks= [100,45,69,43,85,79,45,69,45,90,100]
plt.hist(marks,bins=[0,45,50,70,100],rwidth=0.9,histtype='step')
plt.show()
import matplotlib.pyplot as plt
marks= [100,45,69,43,85,79,45,69,45,90,100]
plt.hist(marks,bins=[0,45,50,70,100],rwidth=0.9, histtype='stepfilled')
plt.show()
OUTPUT
import matplotlib.pyplot as plt
Boys= [10,20,11,21,9]
Girls=[11,23,10,9,6]
plt.hist([Boys,Girls],bins=[0,10,20,30],rwidth=0.9,color=["r","k"],label=["Boys","Girls"])
plt.legend()
plt.show()