pynbody.plot.generic.hist2d

Contents

pynbody.plot.generic.hist2d#

pynbody.plot.generic.hist2d(x, y, weights=None, values=None, gridsize=(100, 100), nbins=None, x_logscale=False, y_logscale=False, x_range=None, y_range=None, use_kde=False, kde_kwargs=None, fill_value=None, **kwargs)[source]#

Plot 2D histogram for arbitrary arrays x and y.

If use_kde is True, instead of a binned histogram, a Gaussian kernel density estimate is used.

It is also possible to obtain an average of specified values which are sampled at the x and y. These can be weighted by weights (e.g. mass) if desired. If weights are provided without values, the result is a simple weighted histogram.

Changed in version 2.1:

  • Added fill_value keyword. If provided, empty bins are filled with this value when making a histogram of mean values. Default is None, in which case empty bins are filled with NaN which will typically be rendered as transparent. Versions prior to 2.1 implicitly had fill_value set to 0.

  • Added colorbar_label and colorbar_format keywords.

Changed in version 2.0: The scalemin and scalemax keywords have been deprecated in favor of vmin and vmax for consistency with matplotlib and other pynbody plotting functions.

The make_plot keyword has been deprecated. Use plot_type instead.

The ret_im keyword has been deprecated. If you want to use imshow instead of contourf, set plot_type to ‘image’.

The mass keyword was confusing and has been deprecated. When mass was provided previously, it was used as the weight, while the weight array was used as the quantity to obtain a mass-weighted average of. So, where previously you would pass weights and mass you now pass values and weights respectively.

The draw_contours keyword has been removed. If you want to overplot mass contours, call the function again using the mass array, with plot_type set to ‘contour’.

Parameters:
  • x (array-like) – x-coordinates of points

  • y (array-like) – y-coordinates of points

  • weights (array-like, optional) – weights of points; if not provided, all points are given equal weight. If combined with values, each pixel is a weighted average of the values in that pixel. If only weights is provided, you get back a

  • values (array-like, optional) – values to assign to each point; if provided, a weighted mean of the value in each pixel is computed

  • gridsize (tuple, optional) – number of bins in each dimension. Default is (100,100).

  • nbins (int, optional) – An alternative way to specify number of bins for the histogram - if specified, gridsize is set to (nbins,nbins).

  • plot_type (str, optional) – If ‘contour’ or ‘contourf’ use matplotlib to make a contour/filled contour. If ‘image’, use matplotlib imshow (default). If ‘none’ (or, for backward compatibility, False), return the histogram data.

  • vmin (float, optional) – Minimum value for the color scale.

  • vmax (float, optional) – Maximum value for the color scale.

  • x_range (array-like, optional) – Length-2 array specifies the x range. Default is None, in which case the range is set to the min and max of x.

  • y_range (array-like, optional) – Length-2 array specifies the y range. Default is None, in which case the range is set to the min and max of y.

  • x_logscale (bool, optional) – If True, the histogram will be made in log x space. Default False.

  • y_logscale (bool, optional) – If True, the histogram will be made in log y space. Default False.

  • nlevels (int | array-like, optional) – Number of levels to use for contours (if plot_type is ‘contour’). Default is 20.

  • logscale (boolean, optional) – If True, use a log-scaled colorbar and log-spaced contours. Default is True.

  • colorbar (boolean, optional) – If True, draw a colorbar. Default is False.

  • colorbar_label (str, optional) – If colorbar is True, this string will be used as the label for the colorbar.

  • colorbar_format (str, optional) – If colorbar is True, this string will be used as the format string for the colorbar.

  • vmin – Minimum value to use for the color scale.

  • vmax – Maximum value to use for the color scale.

  • cmap (str, optional) – Colormap to use. Default is None, which uses the default colormap.

  • make_plot (str, optional) – Deprecated alias for plot_type.

  • use_kde (bool, optional) – If True, use a gaussian kernel density estimate instead of a histogram.

  • kde_kwargs (dict, optional) – Dictionary of keyword arguments to pass to fast_kde() if use_kde is True.

  • fill_value (float, optional) – If provided, fill empty bins with this value when making a histogram of mean values (i.e. only when values is provided). Default is None, in which case empty bins are filled with NaN.

  • ret_im (bool, optional) – Deprecated. If True, plot_type is set to ‘image’.

  • scalemin (float, optional) – Deprecated alias for vmin.

  • scalemax (float, optional) – Deprecated alias for vmax.

  • xlogrange (bool, optional) – Deprecated alias for x_logscale.

  • ylogrange (bool, optional) – Deprecated alias for y_logscale.