I am trying to understanding the following codes
s_time = Slider(ax_time, 'Time', 0, 30, valinit=0)
# if deleting the following part, plot will not move
def update(val):
pos = s_time.val
ax.axis([pos, pos 10, 20, 40])
fig.canvas.draw_idle()
s_time.on_changed(update)
I am confused about
What does 's_time.val' here do? a (slider variable).(input parameter)
Thanks!
CodePudding user response:
s_time
is an instance of the Slider
class. on_changed
is an attribute of the Slider
class. In your code, there would be code similar to this -
class Slider:
...
def on_changed(self,update):
update()
...
So when you make a new Slider
object in a variable called s_time
and call the on_changed
function, it will reference the code inside the class.