das.utils_plot

Plot utilities.

class das.utils_plot.Pdf(savename, autosave=True, style=None, **savefig_kws)[source]

Thin wrapper around Autosaving variant

[summary]

Parameters
  • savename ([type]) – [description]

  • autosave (bool, optional) – [description]. Defaults to True.

  • style ([type], optional) – [description]. Defaults to None.

das.utils_plot.annotate_events(event_seconds, event_names=None, tmin: float = 0, tmax: float = inf, color: Optional[List] = None)[source]

Plot events as vertical lines to plot.

Parameters
  • event_seconds (List[float]) – List of event times in seconds

  • event_names (List[str], optional) – List of event names. Defaults to None.

  • tmin (float, optional) – Start of the range of events annotated in seconds. Defaults to 0.

  • tmax (float, optional) – End of the range of events annotated in seconds. Defaults to np.inf.

  • color (optional) – Either a single valid matplotlib color (in that case all segment types will have that color) or a list of matplotlib colors, one for each segment type. Defaults to None, in which case a list of distinct colors will be created automatically from colorcet’s ‘glasbey_light’ palette.

Raises

ValueError – If the number of colors does not match the number of unique event names.

das.utils_plot.annotate_segments(onset_seconds, offset_seconds, segment_names=None, tmin: float = 0, tmax: float = inf, color=None)[source]

Plot segments as vertical lines to plot.

Parameters
  • onset_seconds ([type]) – [description]

  • offset_seconds ([type]) – [description]

  • segment_names ([type], optional) – [description]. Defaults to None.

  • tmin (float, optional) – [description]. Defaults to 0.

  • tmax (float, optional) – [description]. Defaults to np.inf.

  • color (optional) – Either a single valid matplotlib color (in that case all segment types will have that color) or a list of matplotlib colors, one for each segment type. Defaults to None, in which case a list of distinct colors will be created automatically from colorcet’s ‘glasbey_light’ palette.

Raises

ValueError – If the number of colors does not match the number of unique segment names.

das.utils_plot.bar_text(ax=None, spacing=- 20, to_int=True)[source]

Add labels to the end of each bar in a bar chart.

Parameters
  • ax (matplotlib.axes.Axes) – The matplotlib object containing the axes of the plot to annotate. Defaults to current axis.

  • spacing (int) – The distance between the labels and the bars. Defaults to -20 (inside bar)

das.utils_plot.downsample_plot(x, y, ds=20)[source]

Reduces complexity of exported pdfs w/o impairing visual appearance.

Modified from pyqtgraph - downsampleMethod=peak. Keeps peaks so the envelope of the waveform is preserved.

das.utils_plot.generate_colors(nb_colors: int = 1, start_color=None, start=0, step=1)[source]

[summary]

Parameters
  • nb_colors (int, optional) – [description]. Defaults to 1.

  • start_color ([type], optional) – [description]. Defaults to None.

  • start (int, optional) – [description]. Defaults to 0.

  • step (int, optional) – [description]. Defaults to 1.

Returns

[description]

Return type

[type]

das.utils_plot.imshow_text(data, labels=None, ax=None, color_high='w', color_low='k', color_threshold=50, skip_zeros=False)[source]

Text labels for individual cells of an imshow plot

Parameters
  • data ([type]) – Color values

  • labels ([type], optional) – Text labels. Defaults to None.

  • ax ([type], optional) – axis. Defaults to plt.gca().

  • color_high (str, optional) – [description]. Defaults to ‘w’.

  • color_low (str, optional) – [description]. Defaults to ‘k’.

  • color_threshold (int, optional) – [description]. Defaults to 50.

  • skip_zeros (bool, optional) – [description]. Defaults to False.

das.utils_plot.label_axes(fig=None, labels=None, loc=None, **kwargs)[source]

Walks through axes and labels each.

kwargs are collected and passed to annotate

Parameters
  • fig (Figure) – Figure object to work on

  • labels (iterable or None) – iterable of strings to use to label the axes. If None, lower case letters are used.

  • loc (len=2 tuple of floats) – Where to put the label in axes-fraction units

das.utils_plot.remove_axes(axis=None, all=False, which='tblr')[source]

Remove top & left border around plot or all axes & ticks.

Parameters
  • axis (matplotlib.axes.Axes, optional) – Axes to modify. Defaults to None (currently active axis - plt.gca()).

  • all (bool, optional) – Remove all axes & ticks (True) or top & left border only (False). Defaults to False.

das.utils_plot.scalebar(length, dx=1, units='', label=None, axis=None, location='lower right', frameon=False, **kwargs)[source]

Add scalebar to axis.

Usage:

plt.subplot(122) plt.plot([0,1,2,3], [1,4,2,5]) scalebar(0.5, ‘femtoseconds’, label=’duration’, location=’lower right’)

Parameters
  • length (float) – Length of the scalebar in units of axis ticks - length of 1.0 corresponds to spacing between to major x-ticks

  • dx (int, optional) – Scale factor for length. E.g. if scale factor is 10, the scalebar of length 1.0 will span 10 ticks. Defaults to 1.

  • units (str, optional) – Unit label (e.g. ‘milliseconds’). Defaults to ‘’.

  • label (str, optional) – Title for scale bar (e.g. ‘Duration’). Defaults to None.

  • axis (matplotlib.axes.Axes, optional) – Axes to add scalebar to. Defaults to None (currently active axis - plt.gca()).

  • location (str, optional) – Where in the axes to put the scalebar (upper/lower/’’, left/right/center). Defaults to ‘lower right’.

  • frameon (bool, optional) – Add background (True) or not (False). Defaults to False.

  • kwargs – location=None, pad=None, border_pad=None, sep=None, frameon=None, color=None, box_color=None, box_alpha=None, scale_loc=None, label_loc=None, font_properties=None, label_formatter=None, animated=False):

Returns

Handle to scalebar object

das.utils_plot.tablelegend(ax, col_labels=None, row_labels=None, title_label='', *args, **kwargs)[source]

Place a table legend on the axes.

Creates a legend where the labels are not directly placed with the artists, but are used as row and column headers, looking like this: