hyperspy.drawing._widgets.rectangles module

class hyperspy.drawing._widgets.rectangles.RectangleWidget(axes_manager, **kwargs)

Bases: hyperspy.drawing._widgets.rectangles.SquareWidget, hyperspy.drawing.widget.ResizersMixin

RectangleWidget is a asymmetric, Rectangle-patch based widget, which can be dragged and resized by mouse/keys. For resizing by mouse, it adds a small Rectangle patch on the outer border of the main patch, to serve as resize handles. This feature can be enabled/disabled by the ‘resizers’ property, and the size/color of the handles are set by ‘resize_color’/’resize_pixel_size’.

For optimized changes of geometry, the class implements two methods ‘set_bounds’ and ‘set_ibounds’, to set the geomtry of the rectangle by value and index space coordinates, respectivly. It also adds the ‘width’ and ‘height’ properties for verbosity.

For keyboard resizing, ‘x’/’c’ and ‘y’/’u’ will increase/decrease the size of the rectangle along the first and the second axis, respectively.

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

_get_patch_xy()

Get xy value for Rectangle with position being top left. This value deviates from the ‘position’, as ‘position’ correspond to the center value of the pixel. Here, xy corresponds to the top left of the pixel.

_onmousemove(event)

on mouse motion draw the cursor if picked

_parse_bounds_args(args, kwargs)

Internal utility function to parse args/kwargs passed to set_bounds and set_ibounds.

_set_size(value)

Setter for the ‘size’ property.

Calls _size_changed to handle size change, if the value has changed.

_update_patch_geometry()

Updates all geometry of the patch on the plot.

_update_patch_position()

Updates the position of the patch on the plot.

_validate_geometry(x1=None, y1=None)

Make sure the entire patch always stays within bounds. First the position (either from position property or from x1/y1 arguments), is limited within the bounds. Then, if the bottom/right edges are out of bounds, the position is changed so that they will be at the limit.

The modified geometry is stored, but no change checks are performed. Call _apply_changes after this in order to process any changes (the size might change if it is set larger than the bounds size).

_validate_pos(value)

Constrict the position within bounds.

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, top, width, height)

OR

  • ‘x’/’left’

  • ‘y’/’top’

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

  • ‘h’/’height’, alternatively ‘bottom’ (y+h)

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

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, top, width, height)

OR

  • ‘x’/’left’

  • ‘y’/’top’

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

  • ‘h’/’height’, alternatively ‘bottom’

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

class hyperspy.drawing._widgets.rectangles.SquareWidget(axes_manager, **kwargs)

Bases: hyperspy.drawing.widget.Widget2DBase

SquareWidget is a symmetric, Rectangle-patch based widget, which can be dragged, and resized by keystrokes/code. As the widget is normally only meant to indicate position, the sizing is deemed purely visual, but there is nothing that forces this use. However, it should be noted that the outer bounds only correspond to pure indices for odd sizes.

_onmousemove(event)

on mouse motion move the patch if picked

_set_patch()

Sets the patch to a matplotlib Rectangle with the correct geometry. The geometry is defined by _get_patch_xy, and get_size_in_axes.