Widgets that are designed to work for any of the GUI backends. All of these widgets require you to predefine a matplotlib.axes.Axes
instance and pass that as the first parameter. Matplotlib doesn't try to be too smart with respect to layout -- you will have to figure out how wide and tall you want your Axes to be to accommodate your widget.
Bases: matplotlib.widgets.Widget
Widget connected to a single Axes
.
To guarantee that the widget remains responsive and not garbage-collected, a reference to the object should be maintained by the user.
This is necessary because the callback registry maintains only weak-refs to the functions, which are member functions of the widget. If there are no references to the widget object it may be garbage collected which will disconnect the callbacks.
Axes
The parent axes for the widget.
FigureCanvasBase
The parent figure canvas for the widget.
active
bool
Is the widget active?
Connect a callback function with an event.
This should be used in lieu of figure.canvas.mpl_connect
since this function stores callback ids for later clean up.
Disconnect all events created by this widget.
Bases: matplotlib.widgets.AxesWidget
A GUI neutral button.
For the button to remain responsive you must keep a reference to it. Call on_clicked
to connect to the button.
The matplotlib.axes.Axes
the button renders into.
A matplotlib.text.Text
instance.
The color of the button when not hovering.
The color of the button when hovering.
Axes
The Axes
instance the button will be placed into.
The button text.
The image to place in the button, if not None. The parameter is directly forwarded to imshow
.
The color of the button when not activated.
The color of the button when the mouse is over it.
Remove the callback function with connection id cid.
Connect the callback function func to button click events.
Returns a connection id, which can be used to disconnect the callback.
Bases: matplotlib.widgets.AxesWidget
A GUI neutral set of check buttons.
For the check buttons to remain responsive you must keep a reference to this object.
Connect to the CheckButtons with the on_clicked
method.
Add check buttons to matplotlib.axes.Axes
instance ax.
Axes
The parent axes for the widget.
The labels of the check buttons.
The initial check states of the buttons. The list must have the same length as labels. If not given, all buttons are unchecked.
Remove the observer with connection id cid.
Return a tuple of the status (True/False) of all of the check buttons.
Connect the callback function func to button click events.
Returns a connection id, which can be used to disconnect the callback.
Toggle (activate or deactivate) a check button by index.
Callbacks will be triggered if eventson
is True.
Index of the check button to toggle.
If index is invalid.
Bases: matplotlib.widgets.AxesWidget
A crosshair cursor that spans the axes and moves with mouse cursor.
For the cursor to remain responsive you must keep a reference to it.
matplotlib.axes.Axes
The Axes
to attach the cursor to.
Whether to draw the horizontal line.
Whether to draw the vertical line.
Use blitting for faster drawing if supported by the backend.
See Cursor.
Internal event handler to clear the cursor.
Internal event handler to draw the cursor when the mouse moves.
Bases: matplotlib.widgets.RectangleSelector
Select an elliptical region of an axes.
For the cursor to remain responsive you must keep a reference to it.
Press and release events triggered at the same coordinates outside the selection will clear the selector, except when ignore_event_outside=True
.
Axes
The parent axes for the widget.
A callback function that is called after a release event and the selection is created, changed or removed. It must have the signature:
def onselect(eclick: MouseEvent, erelease: MouseEvent)
where eclick and erelease are the mouse click and release MouseEvent
s that start and complete the selection.
Selections with an x-span less than or equal to minspanx are removed (when already existing) or cancelled.
Selections with an y-span less than or equal to minspanx are removed (when already existing) or cancelled.
Whether to use blitting for faster drawing (if supported by the backend).
Properties with which the ellipse is drawn. See matplotlib.patches.Patch
for valid properties. Default:
dict(facecolor='red', edgecolor='black', alpha=0.2, fill=True)
Whether to interpret minspanx and minspany in data or in pixel coordinates.
MouseButton
, list of MouseButton
, default: all buttons
Button(s) that trigger rectangle selection.
Distance in pixels within which the interactive tool handles can be activated.
Properties with which the interactive handles (marker artists) are drawn. See the marker arguments in matplotlib.lines.Line2D
for valid properties. Default values are defined in mpl.rcParams
except for the default value of markeredgecolor
which will be the same as the edgecolor
property in props.
Whether to draw a set of handles that allow interaction with the widget after it is drawn.
Keyboard modifiers which affect the widget's behavior. Values amend the defaults.
"square" and "center" can be combined.
If True
, the widget can be moved by clicking anywhere within its bounds.
If True
, the event triggered outside the span selector will be ignored.
Rectangle and ellipse selectors
Bases: matplotlib.widgets.AxesWidget
Selection curve of an arbitrary shape.
The selected path can be used in conjunction with contains_point
to select data points from an image.
Unlike LassoSelector
, this must be initialized with a starting point xy, and the Lasso
events are destroyed upon release.
Axes
The parent axes for the widget.
Coordinates of the start of the lasso.
Whether to use blitting for faster drawing (if supported by the backend).
Whenever the lasso is released, the callback function is called and passed the vertices of the selected path.
Bases: matplotlib.widgets._SelectorWidget
Selection curve of an arbitrary shape.
For the selector to remain responsive you must keep a reference to it.
The selected path can be used in conjunction with contains_point
to select data points from an image.
In contrast to Lasso
, LassoSelector
is written with an interface similar to RectangleSelector
and SpanSelector
, and will continue to interact with the axes until disconnected.
Example usage:
ax = plt.subplot() ax.plot(x, y) def onselect(verts): print(verts) lasso = LassoSelector(ax, onselect)
Axes
The parent axes for the widget.
Whenever the lasso is released, the onselect function is called and passed the vertices of the selected path.
Whether to use blitting for faster drawing (if supported by the backend).
Properties with which the line is drawn, see matplotlib.lines.Line2D
for valid properties. Default values are defined in mpl.rcParams
.
MouseButton
or list of MouseButton
, optional
The mouse buttons used for rectangle selection. Default is None
, which corresponds to all buttons.
[Deprecated]
Deprecated since version 3.5:
[Deprecated]
Deprecated since version 3.5:
Bases: object
Some widgets, like the cursor, draw onto the canvas, and this is not desirable under all circumstances, like when the toolbar is in zoom-to-rect mode and drawing a rectangle. To avoid this, a widget can acquire a canvas' lock with canvas.widgetlock(widget)
before drawing on the canvas; this will prevent other widgets from doing so at the same time (if they also try to acquire the lock first).
Return whether drawing is available to o.
Return whether o owns this lock.
Return whether the lock is currently held by an owner.
Release the lock from o.
Bases: matplotlib.widgets.Widget
Provide a vertical (default) and/or horizontal line cursor shared between multiple axes.
For the cursor to remain responsive you must keep a reference to it.
matplotlib.backend_bases.FigureCanvasBase
The FigureCanvas that contains all the axes.
matplotlib.axes.Axes
The Axes
to attach the cursor to.
Use blitting for faster drawing if supported by the backend.
Whether to draw the horizontal line.
Whether to draw the vertical line.
See Multicursor.
Clear the cursor.
Connect events.
Disconnect events.
Bases: matplotlib.widgets._SelectorWidget
Select a polygon region of an axes.
Place vertices with each mouse click, and make the selection by completing the polygon (clicking on the first vertex). Once drawn individual vertices can be moved by clicking and dragging with the left mouse button, or removed by clicking the right mouse button.
In addition, the following modifier keys can be used:
For the selector to remain responsive you must keep a reference to it.
Axes
The parent axes for the widget.
When a polygon is completed or modified after completion, the onselect function is called and passed a list of the vertices as (xdata, ydata)
tuples.
Whether to use blitting for faster drawing (if supported by the backend).
Properties with which the line is drawn, see matplotlib.lines.Line2D
for valid properties. Default:
dict(color='k', linestyle='-', linewidth=2, alpha=0.5)
Artist properties for the markers drawn at the vertices of the polygon. See the marker arguments in matplotlib.lines.Line2D
for valid properties. Default values are defined in mpl.rcParams
except for the default value of markeredgecolor
which will be the same as the color
property in props.
A vertex is selected (to complete the polygon or to move a vertex) if the mouse click is within grab_range pixels of the vertex.
If only one point remains after removing points, the selector reverts to an incomplete state and you can start drawing a new polygon from the existing point.
Cursor move event handler and validator.
The polygon vertices, as a list of (x, y)
pairs.
Bases: matplotlib.widgets.AxesWidget
A GUI neutral radio button.
For the buttons to remain responsive you must keep a reference to this object.
Connect to the RadioButtons with the on_clicked
method.
Add radio buttons to an Axes
.
Axes
The axes to add the buttons to.
The button labels.
The index of the initially selected button.
The color of the selected button.
Remove the observer with connection id cid.
Connect the callback function func to button click events.
Returns a connection id, which can be used to disconnect the callback.
Select button with number index.
Callbacks will be triggered if eventson
is True.
Bases: matplotlib.widgets.SliderBase
A slider representing a range of floating point values. Defines the min and max of the range via the val attribute as a tuple of (min, max).
Create a slider that defines a range contained within [valmin, valmax] in axes ax. For the slider to remain responsive you must maintain a reference to it. Call on_changed()
to connect to the slider event.
Slider value.
The Axes to put the slider in.
Slider label.
The minimum value of the slider.
The maximum value of the slider.
The initial positions of the slider. If None the initial positions will be at the 25th and 75th percentiles of the range.
%-format string used to format the slider values. If None, a ScalarFormatter
is used instead.
Whether the slider interval is closed on the bottom.
Whether the slider interval is closed on the top.
If True the slider can be dragged by the mouse.
If given, the slider will snap to multiples of valstep.
The orientation of the slider.
The color of the background track. The track is accessible for further styling via the track attribute.
Properties of the slider handles. Default values are
Key | Value | Default | Description |
---|---|---|---|
facecolor | color | 'white' | The facecolor of the slider handles. |
edgecolor | color | '.75' | The edgecolor of the slider handles. |
size | int | 10 | The size of the slider handles in points. |
Other values will be transformed as marker{foo} and passed to the Line2D
constructor. e.g. handle_style = {'style'='x'}
will result in markerstyle = 'x'
.
Additional kwargs are passed on to self.poly
which is the Polygon
that draws the slider knob. See the Polygon
documentation for valid property names (facecolor
, edgecolor
, alpha
, etc.).
Connect func as callback function to changes of the slider value.
Function to call when slider is changed. The function must accept a numpy array with shape (2,) as its argument.
Connection id (which can be used to disconnect func).
Set the lower value of the slider to max.
Set the lower value of the slider to min.
Set slider value to val.
Bases: matplotlib.widgets._SelectorWidget
Select a rectangular region of an axes.
For the cursor to remain responsive you must keep a reference to it.
Press and release events triggered at the same coordinates outside the selection will clear the selector, except when ignore_event_outside=True
.
Axes
The parent axes for the widget.
A callback function that is called after a release event and the selection is created, changed or removed. It must have the signature:
def onselect(eclick: MouseEvent, erelease: MouseEvent)
where eclick and erelease are the mouse click and release MouseEvent
s that start and complete the selection.
Selections with an x-span less than or equal to minspanx are removed (when already existing) or cancelled.
Selections with an y-span less than or equal to minspanx are removed (when already existing) or cancelled.
Whether to use blitting for faster drawing (if supported by the backend).
Properties with which the rectangle is drawn. See matplotlib.patches.Patch
for valid properties. Default:
dict(facecolor='red', edgecolor='black', alpha=0.2, fill=True)
Whether to interpret minspanx and minspany in data or in pixel coordinates.
MouseButton
, list of MouseButton
, default: all buttons
Button(s) that trigger rectangle selection.
Distance in pixels within which the interactive tool handles can be activated.
Properties with which the interactive handles (marker artists) are drawn. See the marker arguments in matplotlib.lines.Line2D
for valid properties. Default values are defined in mpl.rcParams
except for the default value of markeredgecolor
which will be the same as the edgecolor
property in props.
Whether to draw a set of handles that allow interaction with the widget after it is drawn.
Keyboard modifiers which affect the widget's behavior. Values amend the defaults.
"square" and "center" can be combined.
If True
, the widget can be moved by clicking anywhere within its bounds.
If True
, the event triggered outside the span selector will be ignored.
>>> import matplotlib.pyplot as plt >>> import matplotlib.widgets as mwidgets >>> fig, ax = plt.subplots() >>> ax.plot([1, 2, 3], [10, 50, 100]) >>> def onselect(eclick, erelease): ... print(eclick.xdata, eclick.ydata) ... print(erelease.xdata, erelease.ydata) >>> props = dict(facecolor='blue', alpha=0.5) >>> rect = mwidgets.RectangleSelector(ax, onselect, interactive=True, props=props) >>> fig.show()
See also: Rectangle and ellipse selectors
Center of rectangle.
Corners of rectangle from lower left, moving clockwise.
Midpoint of rectangle edges from left, moving anti-clockwise.
Return (xmin, xmax, ymin, ymax).
Return an array of shape (2, 5) containing the x (RectangleSelector.geometry[1, :]
) and y (RectangleSelector.geometry[0, :]
) coordinates of the four corners of the rectangle starting and ending in the top left corner.
Bases: matplotlib.widgets.SliderBase
A slider representing a floating point range.
Create a slider from valmin to valmax in axes ax. For the slider to remain responsive you must maintain a reference to it. Call on_changed()
to connect to the slider event.
Slider value.
The Axes to put the slider in.
Slider label.
The minimum value of the slider.
The maximum value of the slider.
The slider initial position.
%-format string used to format the slider value. If None, a ScalarFormatter
is used instead.
Whether the slider interval is closed on the bottom.
Whether the slider interval is closed on the top.
Do not allow the current slider to have a value less than the value of the Slider slidermin.
Do not allow the current slider to have a value greater than the value of the Slider slidermax.
If True the slider can be dragged by the mouse.
If a float, the slider will snap to multiples of valstep. If an array the slider will snap to the values in the array.
The orientation of the slider.
The color of the line at the valinit position. Set to 'none'
for no line.
The color of the background track. The track is accessible for further styling via the track attribute.
Properties of the slider handle. Default values are
Key | Value | Default | Description |
---|---|---|---|
facecolor | color | 'white' | The facecolor of the slider handle. |
edgecolor | color | '.75' | The edgecolor of the slider handle. |
size | int | 10 | The size of the slider handle in points. |
Other values will be transformed as marker{foo} and passed to the Line2D
constructor. e.g. handle_style = {'style'='x'}
will result in markerstyle = 'x'
.
Additional kwargs are passed on to self.poly
which is the Polygon
that draws the slider knob. See the Polygon
documentation for valid property names (facecolor
, edgecolor
, alpha
, etc.).
Connect func as callback function to changes of the slider value.
Function to call when slider is changed. The function must accept a single float as its arguments.
Connection id (which can be used to disconnect func).
Set slider value to val.
Bases: matplotlib.widgets.AxesWidget
The base class for constructing Slider widgets. Not intended for direct usage.
For the slider to remain responsive you must maintain a reference to it.
Remove the observer with connection id cid.
Connection id of the observer to be removed.
Reset the slider to the initial value.
Bases: matplotlib.widgets._SelectorWidget
Visually select a min/max range on a single axis and call a function with those values.
To guarantee that the selector remains responsive, keep a reference to it.
In order to turn off the SpanSelector, set span_selector.active
to False. To turn it back on, set it to True.
Press and release events triggered at the same coordinates outside the selection will clear the selector, except when ignore_event_outside=True
.
matplotlib.axes.Axes
A callback function that is called after a release event and the selection is created, changed or removed. It must have the signature:
def on_select(min: float, max: float) -> Any
The direction along which to draw the span selector.
If selection is less than or equal to minspan, the selection is removed (when already existing) or cancelled.
If True, use the backend-dependent blitting features for faster canvas updates.
Dictionary of matplotlib.patches.Patch
properties. Default:
dict(facecolor='red', alpha=0.5)
Called on mouse move while the span is being selected.
If True, the span stays visible after the mouse is released. Deprecated, use interactive instead.
Whether to draw a set of handles that allow interaction with the widget after it is drawn.
MouseButton
or list of MouseButton
, default: all buttons
The mouse buttons which activate the span selector.
Properties of the handle lines at the edges of the span. Only used when interactive is True. See matplotlib.lines.Line2D
for valid properties.
Distance in pixels within which the interactive tool handles can be activated.
If True
, the widget can be moved by clicking anywhere within its bounds.
If True
, the event triggered outside the span selector will be ignored.
>>> import matplotlib.pyplot as plt >>> import matplotlib.widgets as mwidgets >>> fig, ax = plt.subplots() >>> ax.plot([1, 2, 3], [10, 50, 100]) >>> def onselect(vmin, vmax): ... print(vmin, vmax) >>> span = mwidgets.SpanSelector(ax, onselect, 'horizontal', ... props=dict(facecolor='blue', alpha=0.5)) >>> fig.show()
See also: Span Selector
Connect the major canvas events to methods.
Direction of the span selector: 'vertical' or 'horizontal'.
Return extents of the span selector.
Set SpanSelector to operate on a new Axes.
Bases: matplotlib.widgets.Widget
A tool to adjust the subplot params of a matplotlib.figure.Figure
.
Bases: matplotlib.widgets.AxesWidget
A GUI neutral text input box.
For the text box to remain responsive you must keep a reference to it.
Call on_text_change
to be updated whenever the text changes.
Call on_submit
to be updated whenever the user hits enter or leaves the text entry field.
Axes
The Axes
instance the button will be placed into.
Label for this text box.
Initial value in the text box.
The color of the box.
The color of the box when the mouse is over it.
The distance between the label and the right side of the textbox.
The horizontal location of the text.
Remove the observer with connection id cid.
When the user hits enter or leaves the submission box, call this func with event.
A connection id is returned which can be used to disconnect.
When the text changes, call this func with event.
A connection id is returned which can be used to disconnect.
Bases: object
Control handles for canvas tools.
matplotlib.axes.Axes
Matplotlib axes where tool handles are displayed.
Coordinates of control handles.
Shape of marker used to display handle. See matplotlib.pyplot.plot
.
Additional marker properties. See matplotlib.lines.Line2D
.
Whether to use blitting for faster drawing (if supported by the backend).
Return index and pixel distance to closest index.
Set x and y positions of handles.
Bases: object
Control handles for canvas tools.
matplotlib.axes.Axes
Matplotlib axes where tool handles are displayed.
Positions of handles in data coordinates.
Direction of handles, either 'vertical' or 'horizontal'
Additional line properties. See matplotlib.lines.Line2D
.
Whether to use blitting for faster drawing (if supported by the backend).
Return index and pixel distance to closest handle.
x, y position from which the distance will be calculated to determinate the closest handle
position x, y
Direction of the handle: 'vertical' or 'horizontal'.
Positions of the handle in data coordinates.
Remove the handles artist from the figure.
Set the animated state of the handles artist.
Set x or y positions of handles, depending if the lines are vertical of horizontal.
Set the positions of the handle in data coordinates
Set the visibility state of the handles artist.
Bases: object
Abstract base class for GUI neutral widgets.
Is the widget active?
Get whether the widget is active.
Return whether event should be ignored.
This method should be called at the beginning of any event callback.
Set whether the widget is active.
© 2012–2021 Matplotlib Development Team. All rights reserved.
Licensed under the Matplotlib License Agreement.
https://matplotlib.org/3.5.1/api/widgets_api.html