Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf0530a

Browse files
ianhitimhoffm
andcommitted
More explicit variable names
Co-Authored-By: Tim Hoffmann <[email protected]>
1 parent 266066f commit bf0530a

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

examples/widgets/slider_demo.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020
from matplotlib.widgets import Slider, Button
2121

2222

23-
def fxn(t, amp, freq):
24-
return amp * np.sin(2 * np.pi * freq * t)
23+
# The parametrized function to be plotted
24+
def f(t, amplitude, frequency):
25+
return amplitude * np.sin(2 * np.pi * frequency * t)
2526

2627
t = np.arange(0.0, 1.0, 0.001)
2728

2829
# Define initial parameters
29-
a0 = 5
30-
f0 = 3
30+
init_amplitude = 5
31+
init_frequency = 3
3132

3233
# Create the figure and the `~.Line2D` that we will manipulate
3334
fig, ax = plt.subplots()
34-
line, = plt.plot(t, fxn(t, a0, f0), lw=2)
35+
line, = plt.plot(t, f(t, init_amplitude, init_frequency), lw=2)
3536

3637
axcolor = 'lightgoldenrodyellow'
3738
ax.margins(x=0)
@@ -42,17 +43,29 @@ def fxn(t, amp, freq):
4243
# Make a horizontal slider to control the frequency.
4344
# This slider will snap to discrete values as defind by ``valstep``.
4445
axfreq = plt.axes([0.25, 0.1, 0.65, 0.03], facecolor=axcolor)
45-
freq_slider = Slider(axfreq, 'Freq', 0.1, 30.0, valinit=f0, valstep=5.0)
46+
freq_slider = Slider(
47+
ax=axfreq,
48+
label='Frequency',
49+
valmin=0.1,
50+
valmax=30.0,
51+
valinit=init_amplitude,
52+
valstep=5.0
53+
)
4654

4755
# Make a vertically oriented slider to control the amplitude
4856
axamp = plt.axes([0.1, 0.15, 0.03, 0.65], facecolor=axcolor)
4957
amp_slider = Slider(
50-
axamp, "Amp", 0.1, 10.0, valinit=a0, orientation="vertical"
58+
ax=axamp,
59+
label="Amplitude",
60+
valmin=0.1,
61+
valmax=10.0,
62+
valinit=init_amplitude,
63+
orientation="vertical"
5164
)
5265

5366

5467
def update(val):
55-
line.set_ydata(fxn(t, amp_slider.val, freq_slider.val))
68+
line.set_ydata(f(t, amp_slider.val, freq_slider.val))
5669
fig.canvas.draw_idle()
5770

5871

0 commit comments

Comments
 (0)