Plotting utils

A few useful helper functions

mesmerize.plotting.utils.get_colormap(labels: iter, cmap: str, **kwargs) → collections.OrderedDict[source]

Get a dict for mapping labels onto colors

Any kwargs are passed to auto_colormap()

Parameters:
  • labels – labels for creating a colormap. Order is maintained if it is a list of unique elements.
  • cmap – name of colormap
Returns:

dict of labels as keys and colors as values

mesmerize.plotting.utils.map_labels_to_colors(labels: iter, cmap: str, **kwargs) → list[source]

Map labels onto colors according to chosen colormap

Any kwargs are passed to auto_colormap()

Parameters:
  • labels – labels for mapping onto a colormap
  • cmap – name of colormap
Returns:

list of colors mapped onto the labels

mesmerize.plotting.utils.auto_colormap(n_colors: int, cmap: str = 'hsv', output: str = 'mpl', spacing: str = 'uniform', alpha: float = 1.0) → List[Union[PyQt5.QtGui.QColor, numpy.ndarray]][source]

If non-qualitative map: returns list of colors evenly spread through the chosen colormap. If qualitative map: returns subsequent colors from the chosen colormap

Parameters:
  • n_colors – Numbers of colors to return
  • cmap – name of colormap
  • output – option: ‘mpl’ returns RGBA values between 0-1 which matplotlib likes, option: ‘pyqt’ returns QtGui.QColor instances that correspond to the RGBA values
  • spacing – option: ‘uniform’ returns evenly spaced colors across the entire cmap range option: ‘subsequent’ returns subsequent colors from the cmap
  • alpha – alpha level, 0.0 - 1.0
Returns:

List of colors as either QColor or numpy array with length n_colors

class mesmerize.plotting.utils.WidgetRegistry[source]

Register widgets to conveniently store and restore their states

register(widget: PyQt5.QtWidgets.QWidget, setter: callable, getter: callable, name: str)[source]

Register a widget. The setter and getter methods must be interoperable

Parameters:
  • widget (QtWidgets.QWidget) – widget to register
  • setter (callable) – widget’s method to use for setting its value
  • getter (callable) – widget’s method to use for getting its value. This value must be settable through the specified “setter” method
  • name (str) – a name for this widget
get_state() → dict[source]

Get a dict of states for all registered widgets

set_state(state: dict)[source]

Set all registered widgets from a dict