Complete the code to import the slider widget from matplotlib.
from matplotlib.widgets import [1]
The Slider widget allows interactive sliding control in matplotlib plots.
Complete the code to create a slider with label 'Amplitude' and range from 0 to 10.
slider = Slider(ax=[1], label='Amplitude', valmin=0, valmax=10, valinit=5)
The slider needs an axes object to be placed on. plt.axes with position list defines this area.
Fix the error in the slider update function to correctly update the plot line's y-data.
def update(val): amp = slider.val line.set_ydata([1]) fig.canvas.draw_idle()
The y-data should be the sine wave multiplied by the amplitude slider value.
Fill both blanks to create a button that resets the slider to its initial value when clicked.
button = Button(ax=[1], label='Reset') def reset(event): slider.[2]()
The button needs an axes to be placed on, and calling slider.reset() resets the slider to its initial value.
Fill both blanks to connect the slider and button widgets to update and reset the plot interactively.
slider.on_changed([1]) button.on_clicked([2]) plt.show() # Display the interactive plot
The slider calls the update function when changed, the button calls reset when clicked, and plt.show() displays the plot.