matplotlib.pyplot.hist2d#

matplotlib.pyplot.hist2d(x,y,bins=10,*,range=None,density=False,weights=None,cmin=None,cmax=None,data=None,**kwargs)[source]#

Make a 2D histogram plot.

Parameters:
x, yarray-like, shape (n, )

Input values

binsNone or int or [int, int] or array-like or [array, array]

The bin specification:

  • If int, the number of bins for the two dimensions(nx=ny=bins).

  • If[int,int], the number of bins in each dimension(nx,ny=bins).

  • If array-like, the bin edges for the two dimensions(x_edges=y_edges=bins).

  • If[array,array], the bin edges in each dimension(x_edges,y_edges=bins).

The default value is 10.

rangearray-like shape(2, 2), optional

The leftmost and rightmost edges of the bins along each dimension(if not specified explicitly in the bins parameters):[[xmin,xmax],[ymin,ymax]]. All values outside of this range will beconsidered outliers and not tallied in the histogram.

densitybool, default: False

Normalize histogram. See the documentation for thedensityparameter ofhist for more details.

weightsarray-like, shape (n, ), optional

An array of values w_i weighing each sample (x_i, y_i).

cmin, cmaxfloat, default: None

All bins that has count less thancmin or more thancmax will not bedisplayed (set to NaN before passing topcolormesh) and these countvalues in the return value count histogram will also be set to nan uponreturn.

Returns:
h2D array

The bi-dimensional histogram of samples x and y. Values in x arehistogrammed along the first dimension and values in y arehistogrammed along the second dimension.

xedges1D array

The bin edges along the x-axis.

yedges1D array

The bin edges along the y-axis.

imageQuadMesh
Other Parameters:
cmapstr orColormap, default:rcParams["image.cmap"] (default:'viridis')

The Colormap instance or registered colormap name used to map scalar datato colors.

normstr orNormalize, optional

The normalization method used to scale scalar data to the [0, 1] rangebefore mapping to colors usingcmap. By default, a linear scaling isused, mapping the lowest value to 0 and the highest to 1.

If given, this can be one of the following:

vmin, vmaxfloat, optional

When using scalar data and no explicitnorm,vmin andvmax definethe data range that the colormap covers. By default, the colormap coversthe complete value range of the supplied data. It is an error to usevmin/vmax when anorm instance is given (but using astrnormname together withvmin/vmax is acceptable).

colorizerColorizer or None, default: None

The Colorizer object used to map color to data. If None, a Colorizerobject is created from anorm andcmap.

alpha0<=scalar<=1 orNone, optional

The alpha blending value.

dataindexable object, optional

If given, the following parameters also accept a strings, which isinterpreted asdata[s] ifs is a key indata:

x,y,weights

**kwargs

Additional parameters are passed along to thepcolormesh method andQuadMeshconstructor.

See also

hist

1D histogram plotting

hexbin

2D histogram with hexagonal bins

Notes

Note

This is thepyplot wrapper foraxes.Axes.hist2d.

  • Currentlyhist2d calculates its own axis limits, and any limitspreviously set are ignored.

  • Rendering the histogram with a logarithmic color scale isaccomplished by passing acolors.LogNorm instance to thenormkeyword argument. Likewise, power-law normalization (similarin effect to gamma correction) can be accomplished withcolors.PowerNorm.

Examples usingmatplotlib.pyplot.hist2d#

Exploring normalizations

Exploring normalizations

Histograms

Histograms