I have been trying to get a dynamic plot using imagesc. I have copied some examples I have found. The problem is that if I make another window come in front of the matplotlib wondow the plot window freezes. If I click in the window it will tell me that it is not responding. I have tried to modify several of the examples but all end up where the plot window freeze. I attach the latest code at the end. It will not run as I am including another file I have. Any tips on what the problem is would be very helpful.
Is there any way to use the pylab interface to make dynamic plots?
Svein-Erik
import matplotlib
matplotlib.use("WXAgg")
matplotlib.interactive(True)
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure
from matplotlib.axes import Subplot
from pyFDTD06 import *
import wx
class PlotFigure(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Test embedded wxFigure")
self.fig = Figure((5,4), 75)
self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.canvas, 1, wx.TOP)
# create start/stop buttons
self.button_start = wx.Button(self,-1, " Start ", size=(-1,-1))
self.button_stop = wx.Button(self,-1, " Stop ", size=(-1,-1))
# bind actions to the buttons
self.button_start.Bind(wx.EVT_BUTTON,self.OnStart)
self.button_stop.Bind(wx.EVT_BUTTON, self.OnStop)
# pack the buttons in the Sizer
btnsizer = wx.BoxSizer(wx.HORIZONTAL)
btnsizer.Add(self.button_start, 1, wx.LEFT)
btnsizer.Add(self.button_stop, 1, wx.LEFT)
sizer.Add(btnsizer, 0, wx.TOP)
self.SetSizer(sizer)
self.Fit()
# initialize the data here
self.el = FDTD()
self.el.TIME_STEPS = 100
self.el.initmatrix()
a = self.fig.add_subplot(111)
self.im = a.imshow( self.el.Ex[:,:,22], vmin=-0.002, vmax=0.002)
def OnStop(self):
pass
def OnStart(self,event=None):
for self.el.iteration in range(0, self.el.TIME_STEPS):
self.el.currentSimulatedTime = self.el.dt*self.el.iteration
print "#%d %E sec" %(self.el.iteration,self.el.currentSimulatedTime)
if ( (self.el.iteration % self.el.PLOT_MODULUS) == 0):
self.im.set_array(self.el.Ex[:,:,22])
self.canvas.draw()
self.el.pointsourceEx(45,20,22)
self.el.calcHB()
self.el.calcED()
if __name__ == "__main__":
app = wx.PySimpleApp(0)
frame = PlotFigure()
frame.Show(True)
app.MainLoop()