1212See :doc:`/gallery/widgets/range_slider` for an example of using
1313a ``RangeSlider`` to define a range of values.
1414"""
15+
1516import numpy as np
1617import matplotlib .pyplot as plt
1718from matplotlib .widgets import Slider , Button
@@ -29,14 +30,14 @@ def f(t, amplitude, frequency):
2930
3031# Create the figure and the line that we will manipulate
3132fig , ax = plt .subplots ()
32- line , = plt .plot (t , f (t , init_amplitude , init_frequency ), lw = 2 )
33+ line , = ax .plot (t , f (t , init_amplitude , init_frequency ), lw = 2 )
3334ax .set_xlabel ('Time [s]' )
3435
3536# adjust the main plot to make room for the sliders
36- plt .subplots_adjust (left = 0.25 , bottom = 0.25 )
37+ fig .subplots_adjust (left = 0.25 , bottom = 0.25 )
3738
3839# Make a horizontal slider to control the frequency.
39- axfreq = plt . axes ([0.25 , 0.1 , 0.65 , 0.03 ])
40+ axfreq = fig . add_axes ([0.25 , 0.1 , 0.65 , 0.03 ])
4041freq_slider = Slider (
4142 ax = axfreq ,
4243 label = 'Frequency [Hz]' ,
@@ -46,7 +47,7 @@ def f(t, amplitude, frequency):
4647)
4748
4849# Make a vertically oriented slider to control the amplitude
49- axamp = plt . axes ([0.1 , 0.25 , 0.0225 , 0.63 ])
50+ axamp = fig . add_axes ([0.1 , 0.25 , 0.0225 , 0.63 ])
5051amp_slider = Slider (
5152 ax = axamp ,
5253 label = "Amplitude" ,
@@ -68,7 +69,7 @@ def update(val):
6869amp_slider .on_changed (update )
6970
7071# Create a `matplotlib.widgets.Button` to reset the sliders to initial values.
71- resetax = plt . axes ([0.8 , 0.025 , 0.1 , 0.04 ])
72+ resetax = fig . add_axes ([0.8 , 0.025 , 0.1 , 0.04 ])
7273button = Button (resetax , 'Reset' , hovercolor = '0.975' )
7374
7475
0 commit comments