Timers independent of canvases

Dear all,

The animation code in matplotlib relies on timers to update the animated figures. Currently a new timer is created by calling new_timer on a canvas, as in

f = pylab.figure()
timer = f.canvas.new_timer()

This seems a bit of a wrinkle. For example, you may want to associate a timer with multiple figures, or with no figure at all; also you may want to continue using a timer after a particular figure is closed.

I would therefore propose to make timers independent of canvases. Something like this:

from matplotlib import events
timer = events.Timer()

This has the additional advantage of making the different backends more similar to each other; in the current implementation some backends rely on the canvas when making a timer, while others ignore it.

I have made a branch on github that does exactly this; see

I have verified that the animation examples still work correctly with all backends.

Any comments/suggestions/criticisms? If this seems a good idea, I can make a pull request.

Best,
-Michiel.

No opposition here. The “rationale” behind the original location was:

  1. Easy way to make it properly dependent on the backend

  2. Easy way to get a handle on a widget when necessary (for Tk and Wx IIRC)

However, these were reasons of ease of implementation (aka. laziness) on my part, no real technical reasons that I recall (clearly, since your branch works).

So, +1.

Ryan

···

On Fri, Apr 12, 2013 at 9:32 PM, Michiel de Hoon <mjldehoon@…42…> wrote:

Dear all,

The animation code in matplotlib relies on timers to update the animated figures. Currently a new timer is created by calling new_timer on a canvas, as in

f = pylab.figure()

timer = f.canvas.new_timer()

This seems a bit of a wrinkle. For example, you may want to associate a timer with multiple figures, or with no figure at all; also you may want to continue using a timer after a particular figure is closed.

I would therefore propose to make timers independent of canvases. Something like this:

from matplotlib import events

timer = events.Timer()

This has the additional advantage of making the different backends more similar to each other; in the current implementation some backends rely on the canvas when making a timer, while others ignore it.

I have made a branch on github that does exactly this; see

https://github.com/mdehoon/matplotlib/tree/Timer

I have verified that the animation examples still work correctly with all backends.

Any comments/suggestions/criticisms? If this seems a good idea, I can make a pull request.

Best,

-Michiel.


Precog is a next-generation analytics platform capable of advanced

analytics on semi-structured data. The platform includes APIs for building

apps and a phenomenal toolset for data science. Developers can use

our toolset for easy data analysis & visualization. Get a free account!

http://www2.precog.com/precogplatform/slashdotnewsletter


Matplotlib-devel mailing list

Matplotlib-devel@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Thanks for doing this. This looks like quite an improvement!

Why don't you go ahead and make a pull request. I think on the whole the idea is sound, I just have a few minor comments that can probably be dealt with more efficiently in a PR.

Mike

···

On 04/12/2013 10:32 PM, Michiel de Hoon wrote:

Dear all,

The animation code in matplotlib relies on timers to update the animated figures. Currently a new timer is created by calling new_timer on a canvas, as in

f = pylab.figure()
timer = f.canvas.new_timer()

This seems a bit of a wrinkle. For example, you may want to associate a timer with multiple figures, or with no figure at all; also you may want to continue using a timer after a particular figure is closed.

I would therefore propose to make timers independent of canvases. Something like this:

from matplotlib import events
timer = events.Timer()

This has the additional advantage of making the different backends more similar to each other; in the current implementation some backends rely on the canvas when making a timer, while others ignore it.

I have made a branch on github that does exactly this; see
GitHub - mdehoon/matplotlib at Timer
I have verified that the animation examples still work correctly with all backends.

Any comments/suggestions/criticisms? If this seems a good idea, I can make a pull request.

Best,
-Michiel.

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options

Hi Mike, Ryan,

Thanks for your comments. I have made a pull request; see:

Best,
-Michiel

···

--- On Mon, 4/15/13, Michael Droettboom <mdroe@...31...> wrote:

From: Michael Droettboom <mdroe@...31...>
Subject: Re: [matplotlib-devel] Timers independent of canvases
To: matplotlib-devel@lists.sourceforge.net
Date: Monday, April 15, 2013, 10:56 AM
Thanks for doing this. This
looks like quite an improvement!

Why don't you go ahead and make a pull request. I
think on the whole
the idea is sound, I just have a few minor comments that can
probably be
dealt with more efficiently in a PR.

Mike

On 04/12/2013 10:32 PM, Michiel de Hoon wrote:
> Dear all,
>
> The animation code in matplotlib relies on timers to
update the animated figures. Currently a new timer is
created by calling new_timer on a canvas, as in
>
>>>> f = pylab.figure()
>>>> timer = f.canvas.new_timer()
> This seems a bit of a wrinkle. For example, you may
want to associate a timer with multiple figures, or with no
figure at all; also you may want to continue using a timer
after a particular figure is closed.
>
> I would therefore propose to make timers independent of
canvases. Something like this:
>
>>>> from matplotlib import events
>>>> timer = events.Timer()
> This has the additional advantage of making the
different backends more similar to each other; in the
current implementation some backends rely on the canvas when
making a timer, while others ignore it.
>
> I have made a branch on github that does exactly this;
see
> GitHub - mdehoon/matplotlib at Timer
> I have verified that the animation examples still work
correctly with all backends.
>
> Any comments/suggestions/criticisms? If this seems a
good idea, I can make a pull request.
>
> Best,
> -Michiel.
>
>
------------------------------------------------------------------------------
> Precog is a next-generation analytics platform capable
of advanced
> analytics on semi-structured data. The platform
includes APIs for building
> apps and a phenomenal toolset for data science.
Developers can use
> our toolset for easy data analysis & visualization.
Get a free account!
> http://www2.precog.com/precogplatform/slashdotnewsletter
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> matplotlib-devel List Signup and Options

------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of
advanced
analytics on semi-structured data. The platform includes
APIs for building
apps and a phenomenal toolset for data science. Developers
can use
our toolset for easy data analysis & visualization. Get
a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
matplotlib-devel List Signup and Options