hyperspy.drawing._widgets package¶
Submodules¶
hyperspy.drawing._widgets.circle module¶
-
class
hyperspy.drawing._widgets.circle.
CircleWidget
(axes_manager, **kwargs)¶ Bases:
hyperspy.drawing.widget.Widget2DBase
,hyperspy.drawing.widget.ResizersMixin
CircleWidget is a symmetric, Cicle-patch based widget, which can be dragged, and resized by keystrokes/code.
-
decrease_size
()¶ Decrement all sizes by one step. Applied via ‘size’ property.
-
get_centre
()¶ Get’s the center indices. The default implementation is simply the position + half the size in axes space, which should work for any symmetric widget, but more advanced widgets will need to decide whether to return the center of gravity or the geometrical center of the bounds.
-
get_size_in_indices
()¶ Gets the size property converted to the index space (via ‘axes’ attribute).
-
increase_size
()¶ Increment all sizes by one step. Applied via ‘size’ property.
-
hyperspy.drawing._widgets.horizontal_line module¶
-
class
hyperspy.drawing._widgets.horizontal_line.
HorizontalLineWidget
(axes_manager, **kwargs)¶ Bases:
hyperspy.drawing.widget.Widget1DBase
A draggable, horizontal line widget.
hyperspy.drawing._widgets.label module¶
-
class
hyperspy.drawing._widgets.label.
LabelWidget
(axes_manager)¶ Bases:
hyperspy.drawing.widget.Widget1DBase
A draggable text widget. Adds the attributes ‘string’, ‘text_color’ and ‘bbox’. These are all arguments for matplotlib’s Text artist. The default y-coordinate of the label is set to 0.9.
-
string
¶
-
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 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.
hyperspy.drawing._widgets.range module¶
-
class
hyperspy.drawing._widgets.range.
ModifiableSpanSelector
(ax, **kwargs)¶ Bases:
matplotlib.widgets.SpanSelector
-
contains
(mouseevent)¶
-
dummy
(*args, **kwargs)¶
-
mm_on_press
(event)¶
-
mm_on_release
(event)¶
-
move_left
(event)¶
-
move_rect
(event)¶
-
move_right
(event)¶
-
range
¶
-
release
(event)¶ When the button is realeased, the span stays in the screen and the iteractivity machinery passes to modify mode
-
set_initial
(initial_range=None)¶ Remove selection events, set the spanner, and go to modify mode.
-
switch_left_right
(x, left_to_right)¶
-
turn_off
()¶
-
update_range
()¶
-
-
class
hyperspy.drawing._widgets.range.
RangeWidget
(axes_manager)¶ 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.
-
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)¶ 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.
-
-
hyperspy.drawing._widgets.range.
in_interval
(number, interval)¶
hyperspy.drawing._widgets.rectangles module¶
-
class
hyperspy.drawing._widgets.rectangles.
RectangleWidget
(axes_manager)¶ 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.
-
height
¶
-
on_key_press
(event)¶
-
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).
-
width
¶
-
-
class
hyperspy.drawing._widgets.rectangles.
SquareWidget
(axes_manager)¶ 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.
hyperspy.drawing._widgets.scalebar module¶
-
class
hyperspy.drawing._widgets.scalebar.
ScaleBar
(ax, units, pixel_size=None, color='white', position=None, max_size_ratio=0.25, lw=2, length=None, animated=False)¶ Bases:
object
-
calculate_line_position
(pad=0.05)¶
-
calculate_size
(max_size_ratio=0.25)¶
-
calculate_text_position
(pad=0.01)¶
-
get_units_string
()¶
-
plot_scale
(line_width=1)¶
-
remove
()¶
-
set_color
(c)¶
-
set_length
(length)¶
-
set_tex_bold
()¶
-
hyperspy.drawing._widgets.vertical_line module¶
-
class
hyperspy.drawing._widgets.vertical_line.
VerticalLineWidget
(axes_manager, **kwargs)¶ Bases:
hyperspy.drawing.widget.Widget1DBase
A draggable, vertical line widget.