Welcome, guest | Sign In | My Account | Store | Cart

Simple code to show how to incorporate a pylab plot into wx and then interact with it. This can form the basis of windows/apps that plot various variables that can be changing in the background.

Python, 17 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
import matplotlib
matplotlib.interactive( True )
matplotlib.use( 'WXAgg' )

import wx
import pylab

H = pylab.imshow(pylab.random((10,10)))

def callback(*args):
   H.set_array(pylab.random((10,10)))
   pylab.draw()
   wx.WakeUpIdle() # ensure that the idle event keeps firing

app = wx.PySimpleApp( 0 )
wx.EVT_IDLE(app, callback)
app.MainLoop()