Module: widgets

Inheritance diagram for mpltools.widgets:

RectangleSelector

class mpltools.widgets.RectangleSelector(ax, onselect=None, rectprops=None, mindist=10, **kwargs)

Bases: matplotlib.widgets.RectangleSelector

Widget widget for selecting a rectangular region in a plot.

Unlike matplotlib.widgets.RectangleSelector, this widget remains visible after selection and can be resized using corner and edge handles.

After making the desired selection, press “Enter” to accept the selection and call the onselect callback function.

Note the difference from matplotlib.widgets.RectangleSelector: The callback method onselect is called on “Enter”, not after release of the mouse button. In addition, the onselect function now takes a single argument extents, which is a tuple specifying (xmin, xmax, ymin, ymax) of the rectangle.

TODO: Allow rectangle to flip over itself when resizing.

Parameters :

ax : :class:`matplotlib.axes.Axes

onselect : function

Function accepting rectangle extents as the only argument. If None, print extents of rectangle.

mindist : float

Minimum distance in pixels for selection of a control (i.e. corner or edge) handle.

rectprops : dict

Properties for matplotlib.patches.Rectangle. This class redefines defaults in matplotlib.widgets.RectangleSelector.

kwargs : see matplotlib.widgets.RectangleSelector.

Attributes

extents

Methods

connect_event(event, callback) Connect callback with an event.
disconnect_events() Disconnect all events created by this widget.
get_active() Get status of active mode (boolean variable)
ignore(event) return True if event should be ignored
onkeypress(event)
onmove(event)
press(event)
release(event)
set_active(active) Use this to activate / deactivate the RectangleSelector
set_animated(val)
set_visible(val)
update()
update_background(event) force an update of the background
__init__(ax, onselect=None, rectprops=None, mindist=10, **kwargs)
connect_event(event, callback)

Connect callback with an event.

This should be used in lieu of figure.canvas.mpl_connect since this function stores call back ids for later clean up.

corner_coords

Corners of rectangle from lower left, moving clockwise.

disconnect_events()

Disconnect all events created by this widget.

drawon = True
edge_coords

Midpoint of rectangle edges from lower left, moving clockwise.

eventson = True
extents
get_active()

Get status of active mode (boolean variable)

ignore(event)

return True if event should be ignored

onkeypress(event)
onmove(event)
press(event)
release(event)
set_active(active)

Use this to activate / deactivate the RectangleSelector from your program with an boolean parameter active.

set_animated(val)
set_visible(val)
update()
update_background(event)

force an update of the background

Slider

class mpltools.widgets.Slider(ax, value_range, label='', value=None, on_slide=None, value_fmt='%1.2f', slidermin=None, slidermax=None, dragging=True, pad=0.02)

Bases: matplotlib.widgets.Slider

Slider widget to select a value from a floating point range.

Parameters :

ax : Axes instance

The parent axes for the widget

value_range : (float, float)

(min, max) value allowed for value.

label : str

The slider label.

value : float

Initial value. If None, set to value in middle of value range.

on_slide : function

Callback function for slide event. Function should expect slider value.

value_fmt : str

Format string for formatting the slider text.

slidermin, slidermax : float

Used to contrain the value of this slider to the values of other sliders.

dragging : bool

If True, slider is responsive to mouse.

pad : float

Padding (in axes coordinates) between label/value_fmt and slider.

Attributes

value

Methods

connect_event(event, callback) Connect callback with an event.
disconnect(cid) remove the observer with connection id cid
disconnect_events() Disconnect all events created by this widget.
ignore(event) Return True if event should be ignored.
on_changed(func) When the slider value is changed, call func with the new
reset() reset the slider to the initial value if needed
set_val(value) Set value of slider.
__init__(ax, value_range, label='', value=None, on_slide=None, value_fmt='%1.2f', slidermin=None, slidermax=None, dragging=True, pad=0.02)
connect_event(event, callback)

Connect callback with an event.

This should be used in lieu of figure.canvas.mpl_connect since this function stores call back ids for later clean up.

disconnect(cid)

remove the observer with connection id cid

disconnect_events()

Disconnect all events created by this widget.

drawon = True
eventson = True
ignore(event)

Return True if event should be ignored.

This method (or a version of it) should be called at the beginning of any event callback.

on_changed(func)

When the slider value is changed, call func with the new slider position

A connection id is returned which can be used to disconnect

reset()

reset the slider to the initial value if needed

set_val(value)

Set value of slider.

value

Table Of Contents

Previous topic

Module: util