VOOZH about

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

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


  • Courses
  • Tutorials
  • Interview Prep

Matplotlib.pyplot.hist2d() in Python

Last Updated : 12 Jul, 2025
Matplotlib is a library in Python and it is numerical - mathematical extension for NumPy library. Pyplot is a state-based interface to a Matplotlib module which provides a MATLAB-like interface.

matplotlib.pyplot.hist2d() Function

The hist2d() function in pyplot module of matplotlib library is used to make a 2D histogram plot.
Syntax:matplotlib.pyplot.hist2d(x, y, bins=10, range=None, density=False, weights=None, cmin=None, cmax=None, \*, data=None, \*\*kwargs) Parameters: This method accept the following parameters that are described below:
  • x, y : These parameter are the sequence of data.
  • bins : This parameter is an optional parameter and it contains the integer or sequence or string.
  • range : This parameter is an optional parameter and it the lower and upper range of the bins.
  • density : This parameter is an optional parameter and it contains the boolean values.
  • weights : This parameter is an optional parameter and it is an array of weights, of the same shape as x.
  • cmin : This parameter has all bins that has count less than cmin will not be displayed.
  • cmax : This parameter has all bins that has count more than cmax will not be displayed.
Returns: This returns the following:
  • h :This returns the bi-dimensional histogram of samples x and y.
  • xedges :This returns the bin edges along the x axis.
  • yedges :This returns the bin edges along the y axis.
  • image :This returns the QuadMesh.
Below examples illustrate the matplotlib.pyplot.hist2d() function in matplotlib.pyplot: Example #1: Output: 👁 Image
Example #2:
Output: 👁 Image
Comment
Article Tags: