-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Matplotlib for Python Developers
In all the images that we have encountered so far, we have only plotted lines. Matplotlib has a lot of other plot formats, and we are about to see many of them. We want to introduce first a really nice graph that helps to choose the best chart for the kind of comparison and data we want to show:

Histogram charts are a graphical display of frequencies, represented as bars. They show what portion of the dataset falls into each category, usually specified as non-overlapping intervals. Matplotlib calls those categories bins.
We will use NumPy random.randn()to obtain an array of random numbers in a Gaussian distribution and then plot them in a histogram format using hist() function:
In [1]: import matplotlib.pyplot as plt In [2]: import numpy as np In [3]: y = np.random.randn(1000) In [4]: plt.hist(y); In [5]: plt.show()
The output of this code snippet is displayed in the next screenshot:

Histogram plots group up values into bins of values. By default, hist() uses...