plot_2D_dist

legwork.visualisation.plot_2D_dist(x, y, weights=None, disttype='scatter', fig=None, ax=None, show=True, figsize=(12, 7), xlabel=None, ylabel=None, xlim=None, ylim=None, log_scale=False, color=None, scatter_s=20, **kwargs)[source]

Plot a 2D distribution of x and y

This function is a wrapper for matplotlib.pyplot.scatter() and seaborn.kdeplot().

Parameters
xfloat/int array

Variable to plot on the x axis, should be a 1D array

yfloat/int array

Variable to plot on the y axis, should be a 1D array

weightsfloat/int array

Weights for each variable pair (x, y), must have the same shape

disttype{{ “scatter”, “kde” }}

Which type of distribution plot to use

fig: `matplotlib Figure`

A figure on which to plot the distribution. Both ax and fig must be supplied for either to be used

ax: `matplotlib Axis`

An axis on which to plot the distribution. Both ax and fig must be supplied for either to be used

showboolean

Whether to immediately show the plot or only return the Figure and Axis

figsizetuple

Tuple with size for the x- and y-axis if creating a new figure (i.e. ignored when fig/ax is not None)

xlabelstring

Label for the x axis, passed to Axes.set_xlabel()

ylabelstring

Label for the y axis, passed to Axes.set_ylabel()

xlimtuple

Lower and upper limits for the x axis, passed to Axes.set_xlim()

ylimtuple

Lower and upper limits for the u axis, passed to Axes.set_ylim()

log_scalebool or tuple of bools

Whether to use a log scale for the axes. A single bool is applied to both axes, a tuple is applied to the x- and y-axis respectively.

scatter_sfloat, default=20

Scatter point size, passed as s to a scatter plot and ignored for a KDE

colorstring or tuple

Colour to use for the plot, see https://matplotlib.org/tutorials/colors/colors.html for details on how to specify a colour

**kwargs(if disttype==”scatter”)

Input any of s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, edgecolors or more. See matplotlib.pyplot.scatter() for more details.

**kwargs(if disttype==”kde”)

Input any of gridsize, cut, clip, legend, cumulative, cbar, cbar_ax, cbar_kws, bw_method, hue, palette, hue_order, hue_norm, levels, thresh, bw_adjust, log_scale, fill, label. See seaborn.kdeplot() for more details.

Returns
figmatplotlib Figure

The figure on which the distribution is plotted

axmatplotlib Axis

The axis on which the distribution is plotted