upxo.viz.distribution_plots module
Density plots of one or several samples on a matplotlib axes.
plot_kde draws the Gaussian kernel density estimate of one sample and
plot_kde_overlay draws a density histogram with a kernel density line for
each of several samples. Neither calls tight_layout or draws the canvas,
so that several axes of a figure can be updated before one redraw. Both
return the values that were plotted, so that a caller can keep their range.
- upxo.viz.distribution_plots.histogram_bin_count(values, bin_width: float | None = None) int[source]
Number of histogram bins for
values.Without
bin_width, one bin per 5 values, between 5 and 30. With a bin width (in the units ofvalues), the range divided by it, between 3 and 200; 5 when all values are equal.
- upxo.viz.distribution_plots.plot_kde(ax, values, xlabel: str, title: str, ylabel: str = 'Density', bin_width: float | None = None, xlim=None, ylim=None, font_sizes: dict | None = None) ndarray | None[source]
Clear
axand plot the kernel density estimate ofvalues.Non-finite values are dropped. With fewer than two values, or all values equal, a single value is drawn as a vertical line and no value as a “No data available” note; if the estimate fails a histogram is drawn instead.
- Parameters:
bin_width (float, optional) – In the units of
values. Sets the histogram bin count of the fallback and the kernel bandwidth,bin_width / std(values). By default both are chosen automatically.xlim ((low, high), optional) – Axis limits applied after plotting.
ylim ((low, high), optional) – Axis limits applied after plotting.
font_sizes (dict, optional) – Sizes for “tick”, “title”, “axis” and “legend”;
DEFAULT_FONT_SIZESby default.
- Returns:
The finite values plotted; None if there are none.
- Return type:
ndarray or None
- upxo.viz.distribution_plots.plot_kde_overlay(ax, series, xlabel: str, title: str, ylabel: str = 'Density', bin_width: float | None = None, xlim=None, ylim=None, font_sizes: dict | None = None) ndarray | None[source]
Clear
axand overlay, for each(label, values, color)inseries, a density histogram and a kernel density line.Series without finite values are skipped. The line is drawn when scipy is available and the series has more than three distinct values. Parameters as for
plot_kde; the legend uses the “legend” size, at least 6.- Returns:
The finite values of all series, pooled; None if there are none.
- Return type:
ndarray or None