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=100&url=/
___
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)
se