hyperspy.drawing._widgets.line2d module

class hyperspy.drawing._widgets.line2d.Line2DWidget(axes_manager)

Bases: hyperspy.drawing.widget.ResizableDraggableWidgetBase

A free-form line on a 2D plot. Enables dragging and moving the end points, but also allows rotation of the widget by moving the mouse beyond the end points of the line.

The widget adds the ‘linewidth’ attribute, which is different from the size in the following regards: ‘linewidth’ is simply the width of the patch drawn from point to point. If ‘size’ is greater than 1, it will in principle select a rotated rectangle. If ‘size’ is greater than 4, the bounds of this rectangle will be visualized by two dashed lines along the outline of this rectangle, instead of a single line in the center.

The widget also adds the attributes ‘radius_resize’, ‘radius_move’ and ‘radius_rotate’ (defaults: 5, 5, 10), which determines the picker radius for resizing, aka. moving the edge points (by picking within ‘radius_resize’ from an edge point); for moving (by picking within ‘radius_move’ from the body of the line); and for rotation (by picking within ‘radius_rotate’ of the edge points on the “outside” of the line). The priority is in the order resize, rotate, move; so the ‘radius_rotate’ should always be larger than ‘radius_resize’ if the function is to be accessible (putting it lower is an easy way to disable the functionality).

NOTE: This widget’s internal position does not lock to axes points by
default.

NOTE: The ‘position’ is now a 2D tuple: tuple(tuple(x1, x2), tuple(y1, y2)) NOTE: The ‘size’ property corresponds to line width, so it has a len() of only one.

FUNC_A = 32
FUNC_B = 64
FUNC_MOVE = 1
FUNC_NONE = 0
FUNC_RESIZE = 2
FUNC_ROTATE = 4
FUNC_SIZERS = 8
connect_navigate()

Connect to the axes_manager such that changes in the widget or in the axes_manager are reflected in the other.

get_centre()

Get the line center, which is simply the mean position of its vertices.

get_line_length()

Returns line length in axes coordinates. Requires units on all axes to be the same to make any physical sense.

onpick(event)

Pick, and if picked, figure out which function to apply. Also store pouse position for use by _onmousemove. As rotation does not work very well with incremental rotations, the original points are stored if we’re rotating.

hyperspy.drawing._widgets.line2d.angle_between(v1, v2)

Returns the angle in radians between @D vectors ‘v1’ and ‘v2’:

>>> angle_between((1, 0), (0, 1))

1.5707963267948966 >>> angle_between((1, 0), (1, 0)) 0.0 >>> angle_between((1, 0), (-1, 0)) 3.141592653589793

hyperspy.drawing._widgets.line2d.unit_vector(vector)

Returns the unit vector of the vector.