CustomViewer

class glue.viewers.custom.qt.custom_viewer.CustomViewer(widget_instance)[source]

Bases: object

Base class for custom data viewers.

Users can either subclass this class and override one or more custom methods listed below, or use the glue.custom_viewer() function and decorate custom plot functions.

Custom Plot Methods

The following methods can be overridden:

Method Signatures

Custom methods should use argument names from the following list:

  • The name of a UI element(e.g. keywords passed to glue.custom_viewer(), or class-level variables in subclasses). The value assigned to this argument will be the current UI setting (e.g. bools for checkboxes).
  • axes will contain a matplotlib Axes object
  • roi will contain the ROI a user has drawn (only available for make_selector)
  • state will contain a general-purpose object to store other data
  • style contains the VisualAttributes describing a subset or dataset. Only available for plot_data and plot_subset`
  • subset will contain the relevant Subset object.
    Only available for plot_subset

Defining the UI

Simple widget-based UIs can be specified by providing keywords to custom_viewer() or class-level variables to subsets. The kind of widget to associate with each UI element is determined from it’s type.

Example decorator

v = custom_viewer('Example', checkbox=False)

@v.plot_data
def plot(checkbox, axes):
    axes.plot([1, 2, 3])

Example subclass

class CustomViewerSubset(CustomViewer):
    checkbox = False

    def plot_data(self, checkbox, axes):
        axes.plot([1, 2, 3])

The order of arguments can be listed in any order.

Attributes Summary

make_selector Custom method called to build a SubsetState from an ROI.
name Label to give this widget in the GUI
plot_data Custom method called to show a dataset
plot_subset Custom method called to show a subset
redraw_on_settings_change redraw all layers when UI state changes?
remove_artists auto-delete artists?
select Custom method called to filter data using an ROI.
selections_enabled
settings_changed Custom method called when UI settings change.
setup Custom method called when plot is created
ui

Methods Summary

create_axes(figure) Build a new axes object
create_new_subclass(name, **kwargs) Convenience method to build a new CustomViewer subclass
register_to_hub(hub)
settings() Return a frozen copy of the current settings of the viewer
unregister(hub)
value(key[, layer, view])

Attributes Documentation

make_selector = functools.partial(<bound method CustomViewer._register_override_method of <class 'glue.viewers.custom.qt.custom_viewer.CustomViewer'>>, 'make_selector')

Custom method called to build a SubsetState from an ROI.

See select() for an alternative way to define selections, by returning Boolean arrays instead of SubsetStates.

Functions have access to the roi by accepting an roi argument to this function

name = ''

Label to give this widget in the GUI

plot_data = functools.partial(<bound method CustomViewer._register_override_method of <class 'glue.viewers.custom.qt.custom_viewer.CustomViewer'>>, 'plot_data')

Custom method called to show a dataset

plot_subset = functools.partial(<bound method CustomViewer._register_override_method of <class 'glue.viewers.custom.qt.custom_viewer.CustomViewer'>>, 'plot_subset')

Custom method called to show a subset

redraw_on_settings_change = True

redraw all layers when UI state changes?

remove_artists = True

auto-delete artists?

select = functools.partial(<bound method CustomViewer._register_override_method of <class 'glue.viewers.custom.qt.custom_viewer.CustomViewer'>>, 'select')

Custom method called to filter data using an ROI.

This is an alternative function to make_selector(), which returns a numpy boolean array instead of a SubsetState.

Functions have access to the roi by accepting an roi argument to this function

selections_enabled[source]
settings_changed = functools.partial(<bound method CustomViewer._register_override_method of <class 'glue.viewers.custom.qt.custom_viewer.CustomViewer'>>, 'settings_changed')

Custom method called when UI settings change.

setup = functools.partial(<bound method CustomViewer._register_override_method of <class 'glue.viewers.custom.qt.custom_viewer.CustomViewer'>>, 'setup')

Custom method called when plot is created

ui = {}

Methods Documentation

create_axes(figure)[source]

Build a new axes object Override for custom axes

classmethod create_new_subclass(name, **kwargs)[source]

Convenience method to build a new CustomViewer subclass

Parameters:
  • name – Name of the new viewer
  • kwargs – UI elements in the subclass
register_to_hub(hub)[source]
settings()[source]

Return a frozen copy of the current settings of the viewer

unregister(hub)[source]
value(key, layer=None, view=None)[source]