matplotlib timer

Dave Farrance df at see.replyto.invalid
Thu Oct 1 13:45:06 EDT 2015


Laura Creighton <lac at openend.se> wrote:

>In a message of Thu, 01 Oct 2015 17:36:50 +0100, Dave Farrance writes:
>>I'm trying to set up the basics of a timer-scheduled function in
>>matplotlib and I can't figure out how to stop the timer. Maybe the
>>stop() method is dysfunctional in Ubuntu 14.04 or maybe I'm getting the
>>syntax wrong.
>>
>>If anybody's got matplotlib installed, can you try this code and tell me
>>if it stops after one tick as it should -- or does it continue printing
>>every second without stopping as mine does?
>>
>>#!/usr/bin/env python
>>import matplotlib.pyplot as P
>>def fn():
>>  timer.stop()
>>  print("tick")
>>fig, ax = P.subplots()
>>timer = fig.canvas.new_timer(interval=1000)
>>timer.add_callback(fn)
>>timer.start()
>>P.show()
>> 
>
>debian unstable
>Python 3.4.3+ (default, Jul 28 2015, 13:17:50)
>
>mine ticks forever, too.

Thanks. I've just figured out how to stop the timer.

replace "timer.stop()" with
timer.single_shot = True

Yet the documentation says that it's mandatory for the GUI backend base
to implement stop() but that single_shot is optional. Ho hum.

http://matplotlib.org/api/backend_bases_api.html#matplotlib.backend_bases.TimerBase



More information about the Python-list mailing list