psiaudio.plot module

Defines custom scales that may be useful for plotting audio data

Example

To set the x-axis to show ticks at octave intervals but ensure that the label SI unit is in kHz even if the data SI unit is in Hz:

>>> ax.set_xscale('octave', octaves=0.5, data_si='', label_si='k')
class OctaveFormatter(data_si='', label_si='k', precision=None)

Bases: Formatter

class OctaveLocator(octaves, data_si='', label_si='k', mode='nearest')

Bases: Locator

tick_values(vmin, vmax)

Return the values of the located ticks given vmin and vmax.

Note

To get tick locations with the vmin and vmax values defined automatically for the associated axis simply call the Locator instance:

>>> print(type(loc))
<type 'Locator'>
>>> print(loc())
[1, 2, 3, 4]
class OctaveScale(axis, *, octaves=1, mode='nearest', data_si='', label_si='k', precision=None)

Bases: ScaleBase

get_transform()

Return the .Transform object associated with this scale.

limit_range_for_scale(vmin, vmax, minpos)

Return the range vmin, vmax, restricted to the domain supported by this scale (if any).

minpos should be the minimum positive value in the data. This is used by log scales to determine a minimum value.

name = 'octave'
set_default_locators_and_formatters(axis)

Set the locators and formatters of axis to instances suitable for this scale.

get_color_cycle(n, name='palettable.matplotlib.Viridis_20_r', fmt='matplotlib')

Return an iterator over the specified palettable color scheme that returns colors that can be use for plotting.

Parameters:
  • n (int) – Number of colors needed.

  • name (string) – Name of fully qualified palettable color map (e.g., palettable.matplotlib.Viridis_20_r). The number does not matter for continuous scales since we will be interpolating.

  • fmt ({'matplotlib'}) – Format to return colors in. Select the version that is compatible with the plotting library you are using so you can pass the colors in directly to plot function.

Returns:

Iterator that yields a color in the requested format.

Return type:

iterator

iter_colors(x, *args, **kw)

Like enumerate, but yields colors instead of count.

This only works if the length of the iterable can be determined in advance. Pass in as list(generator) if you are using generators.

Parameters:
  • x (iterable)

  • get_color_cycle. (Additional arguments are passed to)

Returns:

An iterable object. The __next__ method of the iterator returns a tuple containing a color and the value obtained from iterating over iterable.

Return type:

iterator

Examples

Quickly generate a dictionary mapping value to color. Useful for plotting.

>>> values = [0, 10, 20, 40, 80]
>>> value_colors = {value: color for color, value in iter_colors(values)
waterfall_plot(axes, waveforms, waterfall_level='level', scale_method='mean', base_scale_multiplier=1, plotkw=None, x_transform=None, y_scale_bar_size=1, label_offset_x=-0.05, label_fmt=<function <lambda>>)
Parameters:
  • axes (matplotlib Axes instance) – Axes to plot on

  • waveforms (pd.DataFrame) – Waveforms to plot. Must be formatted as a DataFrame with one row per plot. Index must contain at least one level.

  • waterfall_level (str) – Name of level in index indicating the value to show on the plot.

Returns:

transforms – Dictionary mapping waterfall level to the transform used for that level. This can be used to plot additional information for each level.

Return type:

dict