Clear Figure

Hi Guys,

I need to clear the Figure after the user has clicked the some button in PyQt, but when I try to plot the graphics again nothing appear. In ipython it works, but when I try it inside my application it does not work. What am I missing?

Inside my MplCanvas class (actually it is a QWidget - see embedding_in_qt4.py in matplotlib examples file - user_interface) I have this code:

self.fig = Figure(figsize=(self.width, self.height), dpi=dpi)

And then in my main application I'm trying to do:

self.canvas.figure.clf()
self.canvas.draw()
self.canvas.axes.plot([1.,2.,4.])

and nothing is plotted. The Figure is totally gray. I tried to do the same thing in embedding_in_qt4.py example, modifying some parts, but it didn't work too.

Do you have any suggestions?

Thanks!
Best regards,
Bernardo M. Rocha

I guess you need to put draw() after plot()

self.canvas.figure.clf()
self.canvas.axes.plot([1.,2.,4.])
self.canvas.draw()

Let us know if it does not help.

-JJ

···

On Sat, Oct 4, 2008 at 7:17 PM, rocha <bernardo.rocha@...2132...> wrote:

Hi Guys,

I need to clear the Figure after the user has clicked the some button in
PyQt, but when I try to plot the graphics again nothing appear. In
ipython it works, but when I try it inside my application it does not
work. What am I missing?

Inside my MplCanvas class (actually it is a QWidget - see
embedding_in_qt4.py in matplotlib examples file - user_interface) I have
this code:

self.fig = Figure(figsize=(self.width, self.height), dpi=dpi)

And then in my main application I'm trying to do:

self.canvas.figure.clf()
self.canvas.draw()
self.canvas.axes.plot([1.,2.,4.])

and nothing is plotted. The Figure is totally gray. I tried to do the
same thing in embedding_in_qt4.py example, modifying some parts, but it
didn't work too.

Do you have any suggestions?

Thanks!
Best regards,
Bernardo M. Rocha

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi Jae-Joon Lee,

I tried it but unfortunately it didn't work too. After the Figure is cleared I cannot plot again.

I've attached the whole code that I'm trying to do this, I hope it could help a little bit. I modified the original example just to test this feature.

Thanks!
Bernardo M. Rocha

Jae-Joon Lee wrote:

embedding_in_qt4.py (4.25 KB)

···

I guess you need to put draw() after plot()

self.canvas.figure.clf()
self.canvas.axes.plot([1.,2.,4.])
self.canvas.draw()

Let us know if it does not help.

-JJ

On Sat, Oct 4, 2008 at 7:17 PM, rocha <bernardo.rocha@...2132...> wrote:
  

Hi Guys,

I need to clear the Figure after the user has clicked the some button in
PyQt, but when I try to plot the graphics again nothing appear. In
ipython it works, but when I try it inside my application it does not
work. What am I missing?

Inside my MplCanvas class (actually it is a QWidget - see
embedding_in_qt4.py in matplotlib examples file - user_interface) I have
this code:

self.fig = Figure(figsize=(self.width, self.height), dpi=dpi)

And then in my main application I'm trying to do:

self.canvas.figure.clf()
self.canvas.draw()
self.canvas.axes.plot([1.,2.,4.])

and nothing is plotted. The Figure is totally gray. I tried to do the
same thing in embedding_in_qt4.py example, modifying some parts, but it
didn't work too.

Do you have any suggestions?

Thanks!
Best regards,
Bernardo M. Rocha

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

The problem appears to be that you have kept a copy of your old axes
around (self.canvas.axes is not a mpl construct, so it looks like you
have attached an axes instance to your canvas instance). You will
want to either not clear your figure and clear your axes instead

  ax.cla()
  ax.plot([1,2,3])
  canvas.draw()

or clear your figure, create a new axes, plot and then draw

   fig.clf()
   ax = fig.add_subplot(111)
   ax.plot([1,2,3])
   ax.draw()

Be careful with the name "axes" to refer to a single axes instance
attached to your canvas. In the mpl scheme, axes is a list of Axes
instance and is attached to the Figure instance. See for example

  http://matplotlib.sourceforge.net/doc/html/users/artists.html

JDH

···

On Sun, Oct 5, 2008 at 3:50 AM, rocha <bernardo.rocha@...2132...> wrote:

self.canvas.figure.clf()
self.canvas.draw()
self.canvas.axes.plot([1.,2.,4.])

and nothing is plotted. The Figure is totally gray. I tried to do the
same thing in embedding_in_qt4.py example, modifying some parts, but it
didn't work too.

Do you have any suggestions?