[Matplotlib-users] clear figure, ax, etc

2012-04-03 Thread Emmanuel Mayssat
what does figure.clear() do ?
what about ax.clear()?

The doc is kind of sparce.
The 2 function/method above do nothing on my setup.
ax.clear() I was expecting to mean 'erase all the 2DLines'
figure.clear()  I was expecting 'hide all the axes'

Now 

figure.del_axes(self.figure.axes) 
does not do anything either

How can I remove my axes from the figure?

--
Emmanuel
--
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Clear Figure

2008-10-05 Thread rocha

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:

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 [EMAIL PROTECTED] 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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users




#!/usr/bin/env python

# embedding_in_qt4.py --- Simple Qt4 application embedding matplotlib canvases
#
# Copyright (C) 2005 Florent Rougon
#   2006 Darren Dale
#
# This file is an example program for matplotlib. It may be used and
# modified with no restriction; raw copies as well as modified versions
# may be distributed without limitation.

import sys, os, random
from PyQt4 import QtGui, QtCore

from numpy import arange, sin, pi
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

progname = os.path.basename(sys.argv[0])
progversion = 0.1


class MyMplCanvas(FigureCanvas):
Ultimately, this is a QWidget (as well as a FigureCanvasAgg, etc.).
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
# We want the axes cleared every time plot() is called
self.axes.hold(False)

self.compute_initial_figure()

#
FigureCanvas.__init__(self, fig)
self.setParent(parent)

FigureCanvas.setSizePolicy(self,
   QtGui.QSizePolicy.Expanding,
   QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)

def compute_initial_figure(self):
pass


class MyStaticMplCanvas(MyMplCanvas):
Simple canvas with a sine plot.
def compute_initial_figure(self):
t = arange(0.0, 3.0, 0.01)
s = sin(2*pi*t)
self.axes.plot(t, s)


class MyDynamicMplCanvas(MyMplCanvas):
A canvas that updates itself every second with a new plot.
def __init__(self, *args, **kwargs):
MyMplCanvas.__init__(self, *args, **kwargs)
timer = QtCore.QTimer(self)
QtCore.QObject.connect(timer, QtCore.SIGNAL(timeout()), self.update_figure)
timer.start(1000)

def compute_initial_figure(self):
 self.axes.plot([0, 1, 2, 3], [1, 2, 0, 4], 'r')

def update_figure(self):
# Build a list of 4 random integers between 0 and 10 (both inclusive)
l = [ random.randint(0, 10) for i in xrange(4) ]

self.axes.plot([0, 1, 2, 3], l, 'r')
self.draw()

def limpa(self):
self.figure.clf()
self.draw()


class ApplicationWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle(application main window)

self.file_menu = QtGui.QMenu('File', self)
self.file_menu.addAction('Quit', self.fileQuit,
 QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
self.menuBar().addMenu(self.file_menu)

self.help_menu = QtGui.QMenu('Help', self)
self.menuBar().addSeparator()
self.menuBar().addMenu(self.help_menu)

self.help_menu.addAction('About', self.teste)

self.main_widget = QtGui.QWidget(self)

l = QtGui.QVBoxLayout(self.main_widget)
sc = 

Re: [Matplotlib-users] Clear Figure

2008-10-05 Thread John Hunter
On Sun, Oct 5, 2008 at 3:50 AM, rocha [EMAIL PROTECTED] 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?

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

-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Clear Figure

2008-10-04 Thread rocha
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Clear Figure

2008-10-04 Thread Jae-Joon Lee
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 [EMAIL PROTECTED] 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=100url=/
 ___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users


-
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=100url=/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users