Matplotlib - Animations
What is wrong with this code snippet for updating a plot with a slider?
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
fig, ax = plt.subplots()
line, = ax.plot([0, 1, 2], [0, 1, 4])
slider_ax = plt.axes([0.25, 0.1, 0.65, 0.03])
slider = Slider(slider_ax, 'Scale', 0.1, 2.0, valinit=1)
def update(val):
line.set_ydata([y * val for y in [0, 1, 4]])
slider.on_changed(update)
plt.show()