wildboar.utils.plot#

Plotting utilities.

Module Contents#

Classes#

MidpointNormalize

Normalise values with a specified midpoint.

Functions#

plot_frequency_domain(x[, y, ax, n_samples, jitter, ...])

Plot the samples in the freqency domain.

plot_time_domain(x[, y, n_samples, ax, alpha, ...])

Plot the samples in the time domain.

class wildboar.utils.plot.MidpointNormalize(vmin=None, vmax=None, midpoint=None)[source]#

Normalise values with a specified midpoint.

Parameters:
vminfloat, optional

The minumum value.

vmaxfloat, optional

The maximum value.

midpointfloat, optional

The midpoint of the values.

autoscale(A)[source]#

Set vmin, vmax to min, max of A.

autoscale_None(A)[source]#

If vmin or vmax are not set, use the min/max of A to set them.

inverse(value)[source]#

Maps the normalized value (i.e., index in the colormap) back to image data value.

Parameters:
value

Normalized value.

static process_value(value)[source]#

Homogenize the input value for easy and efficient normalization.

value can be a scalar or sequence.

Parameters:
value

Data to normalize.

Returns:
resultmasked array

Masked array with the same shape as value.

is_scalarbool

Whether value is a scalar.

Notes

Float dtypes are preserved; integer types with two bytes or smaller are converted to np.float32, and larger types are converted to np.float64. Preserving float32 when possible, and using in-place operations, greatly improves speed for large arrays.

scaled()[source]#

Return whether vmin and vmax are both set.

wildboar.utils.plot.plot_frequency_domain(x, y=None, *, ax=None, n_samples=100, jitter=False, sample_spacing=1, frequency=False, cmap='Dark2')[source]#

Plot the samples in the freqency domain.

Parameters:
xarray-like of shape (n_sample, n_timestep)

The samples.

yarray-like of shape (n_samples, ), optional

The labels.

axAxes, optional

The matplotlib Axes-object.

n_samplesint, optional

The maximum number of samples to plot. If n_samples is larger than the number of samples in x or None, all samples are plotted.

jitterbool, optional

Add jitter to the amplitude lines.

sample_spacingint, optional

The frequency domain sample spacing.

frequencybool, optional

Show the frequency bins.

cmapstr, optional

The colormap.

Returns:
Axes

The axes object that has been plotted.

Examples

>>> from wildboar.utils.plot import plot_frequency_domain
>>> from wildboar.datasets import load_gun_point
>>> X, y = load_gun_point(X, y)
>>> plot_frequency_domain(X, y, n_sample=10)
wildboar.utils.plot.plot_time_domain(x, y=None, *, n_samples=100, ax=None, alpha=0.5, linewidth=0.5, zorder=-1, cmap='Dark2', show_legend=8)[source]#

Plot the samples in the time domain.

Parameters:
xarray-like of shape (n_sample, n_timestep)

The samples.

yarray-like of shape (n_samples, ), optional

The labels, assumed to be discrete labels.

n_samplesint, optional

The maximum number of samples to plot. If n_samples is larger than the number of samples in x or None, all samples are plotted.

axAxes, optional

The matplotlib Axes-object.

alphafloat, optional

The opacity of the samples.

linewidthfloat, optional

The width of the sample lines.

zorderint, optional

The order where the samples are plotted. By default we plot the samples at -1.

cmapstr, optional

The colormap used to colorize samples according to its label.

show_legendbool or int, optional

Whether the legend of labels are show.

  • if bool, show the legend if y is not None

  • if int, show the legend if the number of labels are lower than the show_legend parameter value

Returns:
Axes

The axes object that has been plotted.

Examples

>>> from wildboar.utils.plot import plot_time_domain
>>> from wildboar.datasets import load_gun_point
>>> X, y = load_gun_point(X, y)
>>> plot_time_domain(X, y, n_sample=10)