I have a simple oscillatory animation with a parameter "amp", which I control
with a slider.
The control works (when I do a mouse-drag on the slider bar), but the slide
bar never actually changes it's position because the reset call fails. 
I don't see why the global statement should have any effect. 
I want the "amp" variable to be common to the slider and the animation. 
I'll include the whole code, it's only about 30 lines of executable code:
====
"""
 A simple example of an animated plot, controlled by a slider
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from matplotlib.widgets import Slider

fig, ax = plt.subplots()
amp = 5
freq = 1
t = np.arange(0.0, 2*np.pi*freq, 0.01)
print("len(t)=", len(t))
# INITIALIZE CURVE
line, = ax.plot(t, amp*np.sin(t), lw=4, color='purple')

# Setup slider

axcolor = 'lightgoldenrodyellow'
axamp  = plt.axes([0.25, 0.15, 0.60, 0.03], axisbg=axcolor)

samp = Slider(axamp, 'Amp', 0.1, 10.0, valinit=amp)

def update(val):
    global amp
    amp = samp.val
#   samp.set_val(amp)
#   samp.reset()     # if no argument given, the value of amp is not
changed.
#   samp.reset(amp)     # If used, amp is changed, the animation continues
with changed amp value, 
                                   # but the slider bar does
                                   # not move and get the error "TypeError:
reset() takes exactly 1 argument (2 given)"

samp.on_changed(update)

def reset(event):
    samp.reset()

## Do the animation

def animate(i):
    line.set_ydata(amp*np.sin(t+(i/10.0)))  # update the data
    return line,

#Init only required for blitting to give a clean slate.
def init():
    line.set_ydata(np.ma.array(t, mask=True))
    return line,

ani = animation.FuncAnimation(fig, animate, np.arange(1, 100000),
init_func=init,
    interval=20, repeat=True, repeat_delay=200, blit=True)
plt.show()




--
View this message in context: 
http://matplotlib.1069221.n5.nabble.com/Possible-bug-in-slider-reset-tp44638p44640.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to