Thank you for the help
I removed the show() command from the loop. Now just calling grid(True)
multiple times. On my machine I narrowed the loop to 57 and it started
happening. At 50 it did not.
Another way I found to trigger this problem is to remove the for loop all
together. Then it just pops up the display. Now grab the window with the
mouse and shake the window continuously around, forcing multiple Paint
events. Eventually it triggers the assert. The application I am developing
using multiple matplotlib windows in an MDI window seems to trigger this
quite easily. Everytime a window is added to the MDIParent all MDIChild
windows gets repainted. Something to do with the paint event.
By the way Kudos for matplotlib. Amazing. I had to dig around the code and
news groups to figure out how to find the user coordinates of a mouse click.
Reading the code opens your eyes the wonderful design that is backend
from matplotlib.matlab import *
t = arange(0.0, 2.0, 0.01)
s = sin(2*pi*t)
l = plot(t, s, linewidth=1.0)
title('About as simple as it gets, folks')
legend('line', loc='upper right')
for i in range(100):
# run the app
app = App()
From: John Hunter [mailto:jdhunter@…4…]
Sent: Monday, June 28, 2004 11:17 PM
To: Schalkwyk, Johan
Subject: Re: [Matplotlib-users] Assertion triggered in wxMemory DC
"Schalkwyk," == Schalkwyk, Johan <Johan.Schalkwyk@...227...>
Schalkwyk,> The code snippet below reproduces the
Schalkwyk,> problem. Basically calling "show()" in a loop forces
Schalkwyk,> repaint of the same window many times. After a while a
Schalkwyk,> strange stack trace appears with the assertion
Schalkwyk,> above. Sometimes the stack trace creates garbage all
Schalkwyk,> over the screen which has to be cleared by repainting
Schalkwyk,> the whole screen.
You should only call show at most once per matplotlib script - for
more information on show see http://matplotlib.sf.net/faq.html#SHOW.
When embedding matplotlib in an application, typically you won't use
show at all.
When embedding matplotlib in a GUI like WX, you should use
canvas.draw() to repaint the figure. See embedding_in_wx.py in the
examples directory of the matplotlib src distribution of the script
embedding_in_wx2.py attached with this email for an example of how to
use matplotlib in a wx app.
I can't promise you this will fix your problem, but will at least make
your example consistent with how matplotlib is meant to be used in a
wx app. If you still get a problem, please post the revised code and
I'll take a look.
An example of how to use wx or wxagg in an application w/o the toolbar
from matplotlib.numerix import arange, sin, pi
# uncomment the following to use wx rather than wxagg
#from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
# comment out the following to use wx rather than wxagg
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as
from matplotlib.figure import Figure
from wxPython.wx import *
self.figure = Figure(figsize=(5,4), dpi=100)
self.axes = self.figure.add_subplot(111)
t = arange(0.0,3.0,0.01)
s = sin(2*pi*t)
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wxBoxSizer(wxVERTICAL)
self.sizer.Add(self.canvas, 1, wxTOP | wxLEFT | wxEXPAND)
# Capture the paint message
def OnPaint(self, event):
'Create the main window and insert the custom frame'
frame = CanvasFrame()
app = App(0)