hyperspy.drawing._widgets.range module

class hyperspy.drawing._widgets.range.RangeWidget(axes_manager, ax=None, color='r', alpha=0.25, **kwargs)

Bases: hyperspy.drawing.widget.ResizableDraggableWidgetBase

RangeWidget is a span-patch based widget, which can be dragged and resized by mouse/keys. Basically a wrapper for ModifiablepanSelector so that it conforms to the common widget interface.

For optimized changes of geometry, the class implements two methods ‘set_bounds’ and ‘set_ibounds’, to set the geometry of the rectangle by value and index space coordinates, respectivly.

Implements the internal method _validate_geometry to make sure the patch will always stay within bounds.

_add_patch_to(ax)

Create and add the matplotlib patches to ‘ax’

_do_snap_position(*args, **kwargs)

Snaps position to axes grid. Returns snapped value. If value is passed as an argument, the internal state is left untouched, if not the position attribute is updated to the snapped value.

_update_patch_geometry()

Updates all geometry of the patch on the plot.

_update_patch_position()

Updates the position of the patch on the plot.

_update_patch_size()

Updates the size of the patch on the plot.

disconnect()

Disconnect from all events (both matplotlib and navigation).

set_bounds(*args, **kwargs)

Set bounds by values. Bounds can either be specified in order left, bottom, width, height; or by keywords:

  • ‘bounds’: tuple (left, width)

OR

  • ‘x’/’left’

  • ‘w’/’width’, alternatively ‘right’ (x+w)

If specifying with keywords, any unspecified dimensions will be kept constant (note: width will be kept, not right).

set_ibounds(*args, **kwargs)

Set bounds by indices. Bounds can either be specified in order left, bottom, width, height; or by keywords:

  • ‘bounds’: tuple (left, width)

OR

  • ‘x’/’left’

  • ‘w’/’width’, alternatively ‘right’

If specifying with keywords, any unspecified dimensions will be kept constant (note: width will be kept, not right).

set_on(value, render_figure=True)

Change the on state of the widget. If turning off, all patches will be removed from the matplotlib axes and the widget will disconnect from all events. If turning on, the patch(es) will be added to the matplotlib axes, and the widget will connect to its default events.