Update some part of a figure

I forgot to say that being under Mac O$, I can use with animate… So I do not know if i can build an infinite animation. Is it possible ?

···

2014-03-12 12:01 GMT+01:00 Christophe Bal <projetmbc@…287…>:

Yes I’ve read it.

  1. It proposes to update infos about the figure, this is what I do in my update function which only change the color of one random rectangle every time that a timer asks to do it.

  2. Then it is said to use plt.draw(), which is what I do. If I use a timer, each draw takes merely 2 seconds for 642 fixed initial squares instead of being very quick for 162 fixed initial squares. It is certain that the draw is indeed a redraw.

2014-03-12 11:49 GMT+01:00 Derek <gamesbook@…287…>:

Did you look at the link; the person updating the plots had the same issue - i.e. he did not know when the data would arrive or how long it would be active for. That sounds like your situation?

On 12 March 2014 11:59, Christophe Bal <projetmbc@…287…> wrote:

I forgot to say that here the use of animations is not good because, I have no max playing time.

2014-03-12 10:56 GMT+01:00 Christophe Bal <projetmbc@…287…>:

Hello.

First of all, I forgot the link to my post : here it is.

Yes, for pedagogical reason, I would like to use matplotlib for beginner programmers, like me :-), such as to do some 80 old school games.

The problem I met using the draw method is that it takes 2 seconds for a figure of 64**2 squares. This is due to the fact that everythin is redraw. Here is my update method.

------------------------------------------------

def update():

global colors, width, height

x = randint(0, width - 1)

y = randint(0, height - 1)

plotgrid[y][x].set_facecolor(choice(colors))

plt.draw()

2014-03-12 10:44 GMT+01:00 Derek <gamesbook@…287…>:

Its not really clear what you are trying to achieve (using Matplotlib to play Tetris??); but this have some pointers:

http://stackoverflow.com/questions/10944621/dynamically-updating-plot-in-matplotlib

On 12 March 2014 11:33, Christophe Bal <projetmbc@…287…> wrote:

Hello.

I’ve poste here a question but no one seems to have an hint to give so I repeat my question here.

In the attached Python 3 code, I draw n**2 squares in black and then I dynamically change in a random way the colors of some squares.

The problem I met is that at each new random choice, I redraw all the squares. I know that it is stupid for large number of squares.

Is there a way to change some propriety of one square, and then to ask to matplotlib to redraw only what have changed ? I’m looking for something similar to blint for animations.

Christophe BAL


Learn Graph Databases - Download FREE O’Reilly Book

“Graph Databases” is the definitive new guide to graph databases and their

applications. Written by three acclaimed leaders in the field,

this first edition is now available. Download your free book today!

http://p.sf.net/sfu/13534_NeoTech


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Hello,
I have a good news for the Mac users who want to play with animations. I’ve reinstalled Maverick OS on my Mac without any softwares, this is called a clean installation, and then I’ve installed Anaconda, and XQuark (see this).

To make animations work, you just have to use the following two lines before any other matplotlib imports.

import matplotlib
matplotlib.use('TkAgg')

I think this will work for any Mac OS supported by Anaconda. The use of XQuark is only needed for Maverick.

···

2014-03-12 12:17 GMT+01:00 Christophe Bal <projetmbc@…287…>:

I forgot to say that being under Mac O$, I can use with animate… So I do not know if i can build an infinite animation. Is it possible ?

2014-03-12 12:01 GMT+01:00 Christophe Bal <projetmbc@…287…>:

Yes I’ve read it.

  1. It proposes to update infos about the figure, this is what I do in my update function which only change the color of one random rectangle every time that a timer asks to do it.

  2. Then it is said to use plt.draw(), which is what I do. If I use a timer, each draw takes merely 2 seconds for 642 fixed initial squares instead of being very quick for 162 fixed initial squares. It is certain that the draw is indeed a redraw.

2014-03-12 11:49 GMT+01:00 Derek <gamesbook@…287…>:

Did you look at the link; the person updating the plots had the same issue - i.e. he did not know when the data would arrive or how long it would be active for. That sounds like your situation?

On 12 March 2014 11:59, Christophe Bal <projetmbc@…287…> wrote:

I forgot to say that here the use of animations is not good because, I have no max playing time.

2014-03-12 10:56 GMT+01:00 Christophe Bal <projetmbc@…287…>:

Hello.

First of all, I forgot the link to my post : here it is.

Yes, for pedagogical reason, I would like to use matplotlib for beginner programmers, like me :-), such as to do some 80 old school games.

The problem I met using the draw method is that it takes 2 seconds for a figure of 64**2 squares. This is due to the fact that everythin is redraw. Here is my update method.

------------------------------------------------

def update():

global colors, width, height

x = randint(0, width - 1)

y = randint(0, height - 1)

plotgrid[y][x].set_facecolor(choice(colors))

plt.draw()

2014-03-12 10:44 GMT+01:00 Derek <gamesbook@…287…>:

Its not really clear what you are trying to achieve (using Matplotlib to play Tetris??); but this have some pointers:

http://stackoverflow.com/questions/10944621/dynamically-updating-plot-in-matplotlib

On 12 March 2014 11:33, Christophe Bal <projetmbc@…287…> wrote:

Hello.

I’ve poste here a question but no one seems to have an hint to give so I repeat my question here.

In the attached Python 3 code, I draw n**2 squares in black and then I dynamically change in a random way the colors of some squares.

The problem I met is that at each new random choice, I redraw all the squares. I know that it is stupid for large number of squares.

Is there a way to change some propriety of one square, and then to ask to matplotlib to redraw only what have changed ? I’m looking for something similar to blint for animations.

Christophe BAL


Learn Graph Databases - Download FREE O’Reilly Book

“Graph Databases” is the definitive new guide to graph databases and their

applications. Written by three acclaimed leaders in the field,

this first edition is now available. Download your free book today!

http://p.sf.net/sfu/13534_NeoTech


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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