ava.plotting package¶
Submodules¶
ava.plotting.grid_plot module¶
Plot a grid of spectrograms.
-
ava.plotting.grid_plot.grid_plot(specs, gap=3, vmin=0.0, vmax=1.0, ax=None, save_and_close=True, filename='temp.pdf')[source]¶ Parameters: - specs (numpy.ndarray) – Spectrograms
- gap (int or tuple of two ints, optional) – The vertical and horizontal gap between images, in pixels. Defaults to 3.
- vmin (float, optional) – Passed to matplotlib.pyplot.imshow. Defaults to 0.0.
- vmax (float, optional) – Passed to matplotlib.pyplot.imshow. Defaults to 1.0.
- ax (matplotlib.pyplot.axis, optional) – Axis to plot figure. Defaults to matplotlib.pyplot.gca().
- save_and_close (bool, optional) – Whether to save and close after plotting. Defaults to True.
- filename (str, optional) – Save the image here.
-
ava.plotting.grid_plot.indexed_grid_plot_DC(dc, indices, ax=None, save_and_close=True, gap=3, side_len=128, filename='grid.pdf')[source]¶ Plot a grid of spectrograms.
Parameters: - dc (ava.data.data_container.DataContainer) – Data container object.
- indices (list of lists of ints) – Spectrogram indices.
- ax (matplotlib.axes._subplots.AxesSubplot or None) – Plotting axis. Defaults to None.
- save_and_close (bool) – Save and close the plot. Defaults to True.
- gap (int) – Number of pixels between spectrograms. Defaults to 3.
- side_len (int) – Spectrogram height and width, in pixels. Defaults to 128.
- filename (str) – Save the image here. Defaults to ‘grid.pdf’.
ava.plotting.latent_projection module¶
Plot a latent mean projection.
-
ava.plotting.latent_projection.latent_projection_plot_DC(dc, embedding_type='latent_mean_umap', color_by=None, title=None, filename='latent.pdf', colorbar=False, colormap='viridis', alpha=0.5, s=0.9, ax=None, cax=None, shuffle=True, save_and_close=True, show_axis=False, default_color='b', condition_func=None)[source]¶ Make a scatterplot of latent means projected to two dimensions.
Parameters: - dc (ava.data.data_container.DataContainer) – See ava.data.data_container.
- embedding_type (str, optional) – Defaults to
'latent_mean_umap'. - color_by ({str, None}, optional) – If
None, all points are coloreddefault_color. Otherwise,color_byis requested from the DataContainer and passed to the matplotlib.pyplot.scatter as the color parameter. The one exception is ifcolor_by == 'filename_lambda', in which case, scatter color is some function of the audio filename, passed tocondition_func. Defaults toNone. - title ({str, None}, optional) – Plot title. Defaults to
None. - filename (str, optional) – Where to save the image, relative to
dc.plots_dir. Defaults to'latent.pdf'. - colorbar (bool, optional) – Whether to include a colorbar. Defaults to
False. - colormap (str, optional) – The pyplot colormap to use if
color_byreturns numerical values. Defaults to'viridis'. - alpha (float, optional) – Alpha value of scatterpoints. Defaults to
0.5. - s (float, optional) – Size of scatterpoints. Defaults to
0.9. - ax ({matplotlib.axes._subplots.AxesSubplot, None}, optional) – Scatter axis. If
None,matplotlib.pyplot.gca()is used. Defaults toNone. - cax ({matplotlib.axes._subplots.AxesSubplot, None}, optional) – Colorbar axis. If
None, an axis is made. Defaults toNone. - shuffle (bool, optional) – Whether to shuffle to zorder of points. Defaults to
True. - save_and_close (bool, optional) – Defaults to
True. - show_axis (bool, optional) – Defaults to
False. - default_color (str, optional) – Defaults to
'b'. - condition_func ({function, None}, optional) – Only used when
color_by == 'filename_lambda', in which casecondition_funcmaps audio filenames to pyplot colors. Defaults toNone.
-
ava.plotting.latent_projection.latent_projection_plot_with_noise_DC(dc, noise_box, embedding_type='latent_mean_umap', color_by=None, title=None, filename='latent.pdf', colorbar=False, colormap='viridis', alpha=0.5, s=0.9, ax=None, cax=None, shuffle=True, save_and_close=True, show_axis=False, default_color='b', condition_func=None)[source]¶ Same as latent_projection_plot_DC, but with noise to exclude.
Parameters: - dc (ava.data.data_container.DataContainer) – See ava.data.data_container.
- noise_box (list of float) – Must contain four elements:
[x1, x2, y1, y2], which are interpreted as a region of the latent mean UMAP embedding containing noise. The points within this rectangle are excluded.
Note
For other parameters, see latent_projection_plot_DC.
-
ava.plotting.latent_projection.projection_plot(embedding, color='b', title=None, save_filename='latent.pdf', colorbar=False, shuffle=True, colormap='viridis', alpha=0.6, s=0.9, ax=None, cax=None, save_and_close=True, show_axis=False)[source]¶ Parameters: - embedding (numpy.ndarray) –
…
- color ({str, numpy.ndarray}, optional) – Defaults to
'b'. - title ({str, None}, optional) – Defaults to
None. - save_filename (str, optional) – Defaults to
'temp.pdf'. - colorbar (bool, optional) –
…
- shuffle (bool, optional) –
…
- embedding (numpy.ndarray) –
ava.plotting.mmd_plots module¶
Maximum Mean Discrepancy plots.
Note
- Because MMD^2 is the value that is directly estimated, this is the value that is saved and passed between functions. In v0.3.0, variable names have been changed to make this distinction clear.
| [1] | Gretton, Arthur, et al. “A kernel two-sample test.” Journal of Machine Learning Research 13. Mar (2012): 723-773. http://www.jmlr.org/papers/volume13/gretton12a/gretton12a.pdf |
-
ava.plotting.mmd_plots.estimate_median_sigma(latent, n=10000, seed=42)[source]¶ Estimate the median pairwise distance for use as a kernel bandwidth.
Parameters: - latent (numpy.ndarray) – Latent means.
- n (int, optional) – Number of random pairs to draw. Defaults to 10000.
- seed ({None, int}) – Random seed. Defaults to
42.
Returns: sigma – Median pairwise Euclidean distance between sampled latent means.
Return type: float
-
ava.plotting.mmd_plots.mmd_matrix_plot(mmd2, cluster=True, cmap='viridis', ax=None, colorbar=True, cax=None, ticks=[0.0, 0.3], filename='mmd_matrix.pdf', save_and_close=True)[source]¶ Plot a pairwise MMD matrix.
Parameters: - mmd2 (numpy.ndarray) – Pairwise MMD^2 values, a square matrix.
- cluster (bool, optional) – Whether to order conditions by a clustering algorithm. Defaults to
True. - cmap (str, optional) – Name of matplotlib colormap. Defaults to
'viridis'. - ax (matplotlib.axes._subplots.AxesSubplot, optional) – Matplotlib axis. Defaults to the current axis,
plt.gca(). - colorbar (bool, optional) – Whether to plot a colorbar. Defaults to
True. - cax (matplotlib.axes._subplots.AxesSubplot or
None, optional) – Colorbar axis. IfNone, a new axis is made. Defaults toNone. - ticks (list of floats, optional) – Colorbar ticks. Defaults to
[0.0, 0.3]. - filename (str, optional) – Where to save plot. Defaults to
'mmd_matrix.pdf'. - save_and_close (bool, optional) – Save and close the figure. Defaults to
True.
-
ava.plotting.mmd_plots.mmd_matrix_plot_DC(dc, condition_from_fn, mmd2_fn, condition_fn, parallel=False, load_data=False, cluster=True, alg='quadratic', max_n=None, sigma=None, cmap='Greys', colorbar=True, cax=None, ticks=[0.0, 0.3], filename='mmd_matrix.pdf', ax=None, save_and_close=True)[source]¶ Plot a pairwise MMD matrix.
Parameters: - dc (ava.data.data_container.DataContainer) – DataContainer object.
- condition_from_fn (function) – Returns an int representing condition, given a filename.
- mmd2_fn (str) – Where MMD^2 values are saved to/loaded from.
- condition_fn (str) – Where conditions are saved to/loaded from.
- parallel (bool, optional) – Whether to calculate different MMD^2 values in parallel. If
True, MMD^2 values are printed out to stdout and can then be saved and formed into a proper matrix using the_matrix_from_txthelper function. - load_data (bool, optional) – Whether to load precomputed data. Defaults to
False. - cluster (bool, optional) – Whether to order conditions by a clustering algorithm. Defaults to
True. - alg ({
'linear','quadratic'}, optional) – Use the linear-time or quadratic time MMD^2 estimate. Defaults to'quadratic'. - max_n (int or
None, optional) – Maximum number of samples from each distribution. IfNone, no maximum is set. Only applies ifalg == 'quadratic'. Defaults toNone. - sigma ({float, None}, optional) – Kernel bandwidth. If
None, the median distance is used. Defaults toNone. - cmap (str, optional) – Name of matplotlib colormap. Defaults to
'viridis'. - colorbar (bool, optional) – Whether to plot a colorbar. Defaults to
True. - cax (matplotlib.axes._subplots.AxesSubplot or
None, optional) – Colorbar axis. IfNone, a new axis is made. Defaults toNone. - ticks (list of floats, optional) – Colorbar ticks. Defaults to
[0.0, 0.3]. - filename (str, optional) – Where to save plot, relative to
dc.plots_dir. Defaults to'mmd_matrix.pdf'. - ax (matplotlib.axes._subplots.AxesSubplot, optional) – Matplotlib axis. Defaults to the current axis,
plt.gca(). - save_and_close (bool, optional) – Whether to save and close the plot. Defaults to
True.
-
ava.plotting.mmd_plots.mmd_tsne_plot_DC(dc, mmd2_fn=None, condition_fn=None, mmd2=None, conditions=None, perplexity=30.0, s=4.0, alpha=0.8, label_func=None, ax=None, save_and_close=True, filename='mmd_tsne.pdf', load_data=False)[source]¶ Compute and plot a t-SNE layout from an MMD matrix.
Either pass
mmd2andconditionsdirectly, or specifymmd2_fnandcondition_fnand setload_data=True.- add option to calculate MMD^2.
Parameters: - dc (ava.data.data_container.DataContainer) – DataContainer object.
- mmd2_fn (str) – Where MMD^2 values are saved to/loaded from.
- condition_fn (str) – Where conditions are saved to/loaded from.
- mmd2 ({numpy.ndarray, None}, optional) – MMD^2 matrix. Defaults to
None. - conditions ({numpy.ndarray, None}, optional) – Condition for each entry of the MMD^2 array. Defaults to
None. - perplexity (float, optional) – Passed to t-SNE. Defaults to
30.0. - s (float, optional) – Passed to
matplotlib.pyplot.scatter. Defaults to4.0. - alpha (float, optional) – Passed to
matplotlib.pyplot.scatter. Defaults to0.8. - label_func ({function, None}, optional) – Maps a conditions to a label (string) for annotating points. Defaults
to
None. - ax (matplotlib.axes._subplots.AxesSubplot, optional) – Matplotlib axis. Defaults to the current axis,
plt.gca(). - save_and_close (bool, optional) – Save and close the figure. Defaults to
True. - filename (str, optional) – Where to save plot. Defaults to
'mmd_tsne.pdf'. - load_data (bool, optional) – Whether to load the MMD^2 and condition data from
mmd2_fnandcondition_fn. Defaults toFalse.
ava.plotting.tooltip_plot module¶
Plot a syllable projection with spectrograms appearing as tooltips.
-
ava.plotting.tooltip_plot.save_image(data, filename)[source]¶ https://fengl.org/2014/07/09/matplotlib-savefig-without-borderframe/
-
ava.plotting.tooltip_plot.tooltip_plot(embedding, images, output_dir='temp', num_imgs=10000, title='', n=30000, grid=False)[source]¶ Create a scatterplot of the embedding with spectrogram tooltips.
- Set the aspect ratio to 1
Parameters: - embedding (numpy.ndarray) – The scatterplot coordinates. Shape: (num_points, 2)
- images (numpy.ndarray) – A spectrogram image for each scatter point. Shape: (num_points, height, width)
- output_dir (str, optional) – Directory where html and jpegs are written. Deafaults to “temp”.
- num_imgs (int, optional) – Number of points with tooltip images. Defaults to 10000.
- title (str, optional) – Title of plot. Defaults to ‘’.
- n (int, optional) – Total number of scatterpoints to plot. Defaults to 30000.
- grid (bool, optional) – Show x and y grid? Defaults to False.
-
ava.plotting.tooltip_plot.tooltip_plot_DC(dc, embedding_type='latent_mean_umap', output_dir='html', num_imgs=1000, title='', n=30000, grid=False, img_format='.jpg')[source]¶ DataContainer version of tooltip_plot.
Parameters: - dc (ava.data.data_container.DataContainer) – See ava.data.data_container for details.
- embedding_type (str, optional) – Defaults to
'latent_mean_umap'. - output_dir (str, optional) – Directory where html and jpegs are written. Deafaults to
'temp'. - num_imgs (int, optional) – Number of points with tooltip images. Defaults to
1000. - title (str, optional) – Title of plot. Defaults to
''. - n (int, optional) – Total number of scatterpoints to plot. Defaults to
30000. - grid (bool, optional) – Show x and y grid? Defaults to
False. - img_format (str, optional) – Filetype for tooltip spectrograms. Defaults to
'.jpg'.