PlotAxes.hist2d

PlotAxes.hist2d(x, y, bins, **kwargs)[source]

Plot a standard 2D histogram. standard 2D histogram.

Parameters
  • *args (y or x, y) – The data passed as positional or keyword arguments. Interpreted as follows:

    • If only y coordinates are passed, try to infer the x coordinates from the Series or DataFrame indices or the DataArray coordinates. Otherwise, the x coordinates are np.arange(0, y.shape[0]).

    • If the y coordinates are a 2D array, plot each column of data in succession (except where each column of data represents a statistical distribution, as with boxplot, violinplot, or when using means=True or medians=True).

    • If any arguments are pint.Quantity, auto-add the pint unit registry to matplotlib’s unit registry using setup_matplotlib. A pint.Quantity embedded in an xarray.DataArray is also supported.

  • bins (int or 2-tuple of int, or array-like or 2-tuple of array-like, optional) – The bin count or exact bin edges for each dimension or both dimensions.

  • weights (array-like, optional) – The weights associated with each point. If string this can be retrieved from data (see below).

  • data (dict-like, optional) – A dict-like dataset container (e.g., DataFrame or DataArray). If passed, positional arguments can optionally be string data keys and the arrays used for plotting are retrieved with data[key]. This is a native matplotlib feature.

  • autoformat (bool, optional) – Whether the x axis labels, y axis labels, axis formatters, axes titles, legend titles, and colorbar labels are automatically configured when a Series, DataFrame, DataArray, or Quantity is passed to the plotting command. Default is rc.autoformat = True. Formatting of pint.Quantity unit strings is controlled by rc.unitformat = 'L'.

Other Parameters
  • cmap (colormap-spec, optional) – The colormap specifer, passed to the Colormap constructor function.

  • cmap_kw (dict-like, optional) – Passed to Colormap.

  • c, color, colors (color-spec or sequence of color-spec, optional) – The color(s) used to create a DiscreteColormap. If not passed, cmap is used.

  • norm (norm-spec, optional) – The continuous colormap normalizer, passed to the Norm constructor function. If discrete is True this is also used to normalize values passed to DiscreteNorm before colors is selected.

  • norm_kw (dict-like, optional) – Passed to Norm.

  • discrete (bool, optional) – If False, then DiscreteNorm is not applied to the colormap. Instead, for non-contour plots, the number of levels will be roughly controlled by rc['cmap.lut']. This has a similar effect to using levels=large_number but it may improve rendering speed. Default is False for imshow, matshow, spy, hexbin, hist2d, and heatmap plots, but True otherwise.

  • sequential, diverging, cyclic, qualitative (bool, optional) – Boolean arguments used if cmap is not passed. Set these to True to use the default rc['cmap.sequential'], rc['cmap.diverging'], rc['cmap.cyclic'], and rc['cmap.qualitative'] colormaps. The diverging option also applies DivergingNorm as the default continuous normalizer.

  • extend ({{'neither', 'min', 'max', 'both'}}, optional) – Whether to assign unique colors to out-of-bounds data and draw colorbar “extensions” when a colorbar is drawn.

  • N – Shorthand for levels.

  • levels (int or sequence of float, optional) – The number of level edges or a sequence of level edges. If the former, locator is used to generate this many level edges at “nice” intervals. If the latter, the levels should be monotonically increasing or decreasing (note that decreasing levels will only work with pcolor plots, not contour plots). Default is rc['cmap.levels'] = 11.

  • values (int or sequence of float, optional) – The number of level centers or a sequence of level centers. If the former, locator is used to generate this many level centers at “nice” intervals. If the latter, levels are inferred using edges. This will override any levels input.

  • vmin, vmax (float, optional) – Used to determine level locations if levels or values is an integer. Actual levels may not fall exactly on vmin and vmax, but the minimum level will be no smaller than vmin and the maximum level will be no larger than vmax. If vmin or vmax are not provided, the minimum and maximum data values are used.

  • robust (bool, float, or 2-tuple, optional) – If True and vmin or vmax were not provided, they are determined from the 2nd and 98th data percentiles rather than the minimum and maximum. If float, this percentile range is used (for example, 90 corresponds to the 5th to 95th percentiles). If 2-tuple of float, these specific percentiles should be used. This feature is useful when your data has large outliers. Default is rc['cmap.robust'] = False.

  • inbounds (bool, optional) – If True and vmin or vmax were not provided, when axis limits have been explicitly restricted with set_xlim or set_ylim, out-of-bounds data is ignored. Default is rc['cmap.inbounds'] = True. See also rc['axes.inbounds'].

  • locator (locator-spec, optional) – The locator used to determine level locations if levels or values is an integer. Passed to the Locator constructor. Default is MaxNLocator with levels integer levels.

  • locator_kw (dict-like, optional) – Passed to Locator.

  • symmetric (bool, optional) – If True, automatically generated levels are symmetric about zero. Default is always False.

  • positive (bool, optional) – If True, automatically generated levels are positive with a minimum at zero. Default is always False.

  • negative (bool, optional) – If True, automatically generated levels are negative with a maximum at zero. Default is always False.

  • nozero (bool, optional) – If True, 0 is removed from the level list. This is mainly useful for single-color contour plots.

  • label (str, optional) – The legend label to be used for this object. In the case of contours, this is paired with the the central artist in the artist list returned by matplotlib.contour.ContourSet.legend_elements.

  • labels (bool, optional) – Whether to apply labels to contours and grid boxes. The text will be white when the luminance of the underlying filled contour or grid box is less than 50 and black otherwise.

  • labels_kw (dict-like, optional) – Ignored if labels is False. Extra keyword args for the labels. For contour plots, this is passed to clabel. Otherwise, this is passed to text.

  • fmt (format-spec, optional) – The Formatter used to format number labels. Passed to the Formatter constructor.

  • precision (int, optional) – The maximum number of decimal places for number labels generated with the default formatter Simpleformatter.

  • colorbar (bool, int, or str, optional) – If not None, this is a location specifying where to draw an inner or outer colorbar from the resulting object(s). If True, the default rc['colorbar.loc'] = 'right' is used. If the same location is used in successive plotting calls, object(s) will be added to the existing colorbar in that location (valid for colorbars built from lists of artists). Valid locations are shown in in colorbar.

  • colorbar_kw (dict-like, optional) – Extra keyword args for the call to colorbar.

  • legend (bool, int, or str, optional) – Location specifying where to draw an inner or outer legend from the resulting object(s). If True, the default rc['legend.loc'] = 'best' is used. If the same location is used in successive plotting calls, object(s) will be added to existing legend in that location. Valid locations are shown in legend.

  • legend_kw (dict-like, optional) – Extra keyword args for the call to legend.

  • **kwargs – Passed to hist2d.