smpl.plot.Slider¶
- class smpl.plot.Slider(ax, label, valmin, valmax, valinit=0.5, valfmt=None, closedmin=True, closedmax=True, slidermin=None, slidermax=None, dragging=True, valstep=None, orientation='horizontal', *, initcolor='r', track_color='lightgrey', handle_style=None, **kwargs)[source]¶
Bases:
SliderBaseA 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.Attributes¶
- valfloat
Slider value.
- __init__(ax, label, valmin, valmax, valinit=0.5, valfmt=None, closedmin=True, closedmax=True, slidermin=None, slidermax=None, dragging=True, valstep=None, orientation='horizontal', *, initcolor='r', track_color='lightgrey', handle_style=None, **kwargs)[source]¶
Parameters¶
- axAxes
The Axes to put the slider in.
- labelstr
Slider label.
- valminfloat
The minimum value of the slider.
- valmaxfloat
The maximum value of the slider.
- valinitfloat, default: 0.5
The slider initial position.
- valfmtstr, default: None
%-format string used to format the slider value. If None, a .ScalarFormatter is used instead.
- closedminbool, default: True
Whether the slider interval is closed on the bottom.
- closedmaxbool, default: True
Whether the slider interval is closed on the top.
- sliderminSlider, default: None
Do not allow the current slider to have a value less than the value of the Slider slidermin.
- slidermaxSlider, default: None
Do not allow the current slider to have a value greater than the value of the Slider slidermax.
- draggingbool, default: True
If True the slider can be dragged by the mouse.
- valstepfloat or array-like, default: None
If a float, the slider will snap to multiples of valstep. If an array the slider will snap to the values in the array.
- orientation{‘horizontal’, ‘vertical’}, default: ‘horizontal’
The orientation of the slider.
- initcolorcolor, default: ‘r’
The color of the line at the valinit position. Set to
'none'for no line.- track_colorcolor, default: ‘lightgrey’
The color of the background track. The track is accessible for further styling via the track attribute.
- handle_styledict
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 inmarkerstyle = 'x'.
Notes¶
Additional kwargs are passed on to
self.polywhich is the ~matplotlib.patches.Polygon that draws the slider knob. See the .Polygon documentation for valid property names (facecolor,edgecolor,alpha, etc.).
Methods
__init__(ax, label, valmin, valmax[, ...])Parameters ax Axes The Axes to put the slider in.
connect_event(event, callback)Connect a callback function with an event.
disconnect(cid)Remove the observer with connection id cid.
Disconnect all events created by this widget.
Get whether the widget is active.
ignore(event)Return whether event should be ignored.
on_changed(func)Connect func as callback function to changes of the slider value.
reset()Reset the slider to the initial value.
set_active(active)Set whether the widget is active.
set_val(val)Set slider value to val.
Attributes
Is the widget active?
drawoneventson- property active¶
Is the widget active?
- connect_event(event, callback)¶
Connect a callback function with an event.
This should be used in lieu of
figure.canvas.mpl_connectsince this function stores callback ids for later clean up.
- disconnect(cid)¶
Remove the observer with connection id cid.
Parameters¶
- cidint
Connection id of the observer to be removed.
- disconnect_events()¶
Disconnect all events created by this widget.
- get_active()¶
Get whether the widget is active.
- ignore(event)¶
Return whether event should be ignored.
This method should be called at the beginning of any event callback.
- on_changed(func)[source]¶
Connect func as callback function to changes of the slider value.
Parameters¶
- funccallable
Function to call when slider is changed. The function must accept a single float as its arguments.
Returns¶
- int
Connection id (which can be used to disconnect func).
- reset()¶
Reset the slider to the initial value.
- set_active(active)¶
Set whether the widget is active.