matplotlib.widgets.Slider#
- classmatplotlib.widgets.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 fromvalmin tovalmax in Axesax. For the slider toremain responsive you must maintain a reference to it. Call
on_changed()to connect to the slider event.- Attributes:
- valfloat
Slider value.
- 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
The way to format the slider value. If a string, it must be in %-format.If a callable, it must have the signature
valfmt(val:float)->str.If None, aScalarFormatteris used.- 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 thanthe value of the Sliderslidermin.
- slidermaxSlider, default: None
Do not allow the current slider to have a value greater thanthe value of the Sliderslidermax.
- 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 ofvalstep.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 thevalinit position. Set to
'none'for no line.- track_colorcolor, default: 'lightgrey'
The color of the background track. The track is accessible forfurther styling via thetrack 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
Line2Dconstructor. e.g.handle_style={'style'='x'}willresult inmarkerstyle='x'.
Notes
Additional kwargs are passed on to
self.polywhich is theRectanglethat draws the slider knob. See theRectangledocumentation for valid property names (facecolor,edgecolor,alpha, etc.).