How it works...

The following is the explanation of the code: 

  • grp_exp is a NumPy array containing experience data in number of years.
  • This data is divided into 21 bins of equal size, by specifying nbins = 21.
  • plt.hist() plots the histogram with grp_exp and nbins as arguments. It returns three parameters, n, bins, and patches. n is the list containing the number of items in each bin, bins is another list specifying starting point of the bin, and patches is the list of objects for each bin. These can be used for any other purpose later in the program.
  • Add the title, and the x and y axis labels, before displaying the histogram on the screen.
  • plt.axvline() plots a vertical line at the mean value of the data, just to represent how the data is distributed on either side of the mean value. Here is how the output looks: