VOOZH about

URL: https://www.geeksforgeeks.org/python/matplotlib-pyplot-hist-in-python/

⇱ Matplotlib.pyplot.hist() in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Matplotlib.pyplot.hist() in Python

Last Updated : 18 Mar, 2026

matplotlib.pyplot.hist() function is used to create histograms, which are graphical representations of data distribution. It divides the data into bins (non-overlapping intervals) and counts the frequency of values in each bin, plotting them as bars.

Lets consider the data values and visualise histogram with help of an example:

Output

👁 Screenshot-2024-12-04-130555
Histogram with hist() with default parameters

Syntax

matplotlib.pyplot.hist(x, bins=None, range=None, density=False, histtype='bar', color=None, label=None)

Parameters:

  • x: data to be represented in the histogram.
  • bins: Specifies the number of bins or the bin edges for the histogram.
  • range: The lower and upper range of the bins.
  • density: If True, the histogram is normalized to form a probability density.
  • histtype: Defines the type of histogram (e.g., 'bar' for a traditional bar histogram).
  • color: Sets the color of the bars.
  • label: Label for the histogram, used in legends.

Create a Histogram in Matplotlib

Example 1: In this example, we will create a histogram and pass the necessary parameters such as bins, color, density, etc.

Output

👁 Screenshot-2024-12-05-180917
Creating the histogram

Note: In this example, density=True is used in plt.hist(). When this parameter is enabled, histogram is normalized and y-axis represents probability density instead of frequency counts. Because of this, values on the vertical axis may appear as decimal numbers instead of whole numbers.

Example 2: In this example, we will create a histogram with different attributes using matplotlib.pyplot.hist() function. We define a specific set of colors for the bars of the histogram bars.

Output

👁 Screenshot-2024-12-04-151553
different color bars in matplot.pyplot.hist()
Comment
Article Tags: