Assertion triggered in wxMemory DC

I’ve been using matplotlib in a WX application. The
particular application can uses many matplotlib figures within a MDI window
class. The problem appears when there are about seven windows active in the
MDI, and an eight is added. This causes a repaint of all seven matplotlib figures,
which then triggers the following assertion

PyAssertionError: C++ assertion “wxAssertFailure”
failed in "…\src\msw\dcmemory.cpp (133): Couldn’t select a bitmap
into wxMemoryDC

This appears on windows XP professional, Python 2.3, wxPython, matplotlib 0.54.

The code snippet below reproduces the problem. Basically
calling “show()” in a loop forces repaint of the same window many
times. After a while a strange stack trace appears with the assertion above.
Sometimes the stack trace creates garbage all over the screen which has to be
cleared by repainting the whole screen.

import wx

import matplotlib


from matplotlib.matlab import *

class App(wx.App):



def OnInit(self):

    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’)


loc=‘upper right’)

    for i in




    # end for


    return True


run the app

app = App()