From: Leighton P. <lp...@sc...> - 2005-03-24 14:37:07
|
Hi,=0D=0A=0D=0AMany thanks (again) to Matt for his suggestions - I had a "D= 'oh" moment=0D=0Awhen it was pointed out where I was calling the update fro= m.=0D=0A=0D=0AMatt's solution works on OS X, but I'm afraid I didn't specif= y what my=0D=0Agoal was particularly well. I'm aiming to dynamically updat= e a=0D=0Amatplotlib plot embedded within a wx.Panel (or wx.Frame) from anot= her=0D=0Aobject, whose internal state is changing so that the calling objec= t's=0D=0Ainternal state is reflected in the matplotlib plot. The wx.Timer=0D= =0Asolution doesn't seem appropriate for that (though if I'm wrong, I'm=0D=0A= happy to take advice).=0D=0A=0D=0AAfter some reading around, I worked up tw= o alternatives for updating the=0D=0Aplot from another object.=0D=0A=0D=0A1= ) wx.Timer, as per Matt=0D=0A2) Loop, and pass the value of the loop counte= r=0D=0A3) A custom wx event, bound to the update method=0D=0A=0D=0AThe code= at http://widdowquinn.pwp.blueyonder.co.uk/wxtest.py implements=0D=0Aall t= hree methods, and how effective they are appears to be OS-=0D=0Adependent:=0D= =0A=0D=0AThe wx.Timer method works on Windows (XP SP2), Linux (FC3) and OS = X=0D=0A(10.3)=0D=0A=0D=0AThe Loop method and custom event methods work fine= on Windows. On=0D=0ALinux, they dynamically update the plot, but not the = button label. On=0D=0AOS X, they do nothing, and only appear to update the= plot after the=0D=0Aloops end.=0D=0A=0D=0ADoes anyone here have any ideas = on how I could progress further on=0D=0Agetting this to run, and update cor= rectly under OS X=3F Or should I go=0D=0Aand bug the wxPython-Users list a= bout it=3F ;)=0D=0A=0D=0AFor info, all three systems are using Python 2.3.5= =2E, matplotlib 0.73.1,=0D=0Aand wxPython 2.5.3.1.=0D=0A=0D=0ACheers,=0D=0A=0D= =0A--=20=0D=0ADr Leighton Pritchard AMRSC=0D=0AD131, Plant-Pathogen Interac= tions, Scottish Crop Research Institute=0D=0AInvergowrie, Dundee, Scotland,= DD2 5DA, UK=0D=0AT: +44 (0)1382 562731 x2405 F: +44 (0)1382 568578=0D=0AE:= lp...@sc... W: http://bioinf.scri.sari.ac.uk/lp=0D=0AGPG/PGP:= FEFC205C E58BA41B http://www.keyserver.net =20=0D=0A(If the si= gnature does not verify, please remove the SCRI disclaimer)=0D=0A_ _ _ _ _ = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _=0D=0A=0D=0A= DISCLAIMER:=0D=0A=0D=0AThis email is from the Scottish Crop Research Instit= ute, but the views=20=0D=0Aexpressed by the sender are not necessarily the = views of SCRI and its=20=0D=0Asubsidiaries. This email and any files trans= mitted with it are confidential=20=0D=0Ato the intended recipient at the e-= mail address to which it has been=20=0D=0Aaddressed. It may not be disclos= ed or used by any other than that addressee.=0D=0AIf you are not the intend= ed recipient you are requested to preserve this=20=0D=0Aconfidentiality and= you must not use, disclose, copy, print or rely on this=20=0D=0Ae-mail in = any way. Please notify pos...@sc... quoting the=20=0D=0Aname = of the sender and delete the email from your system.=0D=0A=0D=0AAlthough SC= RI has taken reasonable precautions to ensure no viruses are=20=0D=0Apresen= t in this email, neither the Institute nor the sender accepts any=20=0D=0Ar= esponsibility for any viruses, and it is your responsibility to scan the em= ail=20=0D=0Aand the attachments (if any).=0D=0A |
From: Matt N. <new...@ca...> - 2005-03-25 04:50:21
|
Hi Leighton, > The Loop method and custom event methods work fine on Windows. > On Linux, they dynamically update the plot, but not the button > label. On OS X, they do nothing, and only appear to update > the plot after the loops end. I'm no expert in wxPython or matplotlib, but there are a few possible problems with your script: - For the timing method, I think the issue is simply how fast you can send Timer events. You're doing them every 20ms, which is pretty fast (I'm willing to take the blame for sending you an example that goes that fast!). If you change that to 200ms, I'll bet you will see more updates. - The Loop method runs a for-loop which may not allow other wx events to be processed, such as changing a Button label. - The Custom Event uses a python for-loop, so I think it's not very different from the Loop method in that it's liable to drop events. For all these, I would think that adding self.Update() should help. This is supposed to repaint the whole wxWidget. That will take time, but should really update all widgets. But it seems that this is not foolproof, and that it can lose events: I don't know why this is. > Matt's solution works on OS X, but I'm afraid I didn't specify > what my goal was particularly well. I'm aiming to dynamically > update a matplotlib plot embedded within a wx.Panel (or > wx.Frame) from another object, whose internal state is > changing so that the calling object's internal state is > reflected in the matplotlib plot. The wx.Timer solution > doesn't seem appropriate for that (though if I'm wrong, I'm > happy to take advice). > > After some reading around, I worked up two alternatives for > updating the plot from another object. > > 1) wx.Timer, as per Matt > 2) Loop, and pass the value of the loop counter > 3) A custom wx event, bound to the update method I think you want to avoid the Loop method, as it can block other widget events. I believe that what you want is to replot the figure when (a) the data has changed and (b) some minimum time has elapsed since the last drawing. One approach is to use a timer to periodically check (this sets the minimun time) for new data, and redraw the plot when there's new data. Another approach is to trigger on changes in the data, possibly saving the timestamp when a redraw is done so as to not draw too often. Which method to use probably depends on how easily it is to detect and act upon changes to the data. Finally, you may also consider putting the data-intensive code in a separate thread from the GUI. But I think the main issue is to not try to redraw the plot 50 times per second. ;). Hope that helps, --Matt |
From: Leighton P. <lp...@sc...> - 2005-03-25 14:24:20
|
Hi Matt,=0D=0A=0D=0AOn Thu, 2005-03-24 at 22:48 -0600, Matt Newville wrote:=0D= =0A> I'm no expert in wxPython or matplotlib, but there are a few=0D=0A> po= ssible problems with your script:=0D=0A> - For the timing method, I think = the issue is simply how fast=20=0D=0A> you can send Timer events. You'r= e doing them every 20ms,=20=0D=0A> which is pretty fast (I'm willing to = take the blame for=20=0D=0A> sending you an example that goes that fast!= ). If you change =20=0D=0A> that to 200ms, I'll bet you will see more u= pdates.=20=0D=0A=0D=0AThe timer was working pretty well on all three system= s at 20ms intervals=0D=0A- no blame to apportion there! ;)=0D=0A=0D=0A> - = The Loop method [...]=0D=0A> - The Custom Event [...]=0D=0A> For all these= , I would think that adding=0D=0A> self.Update()=0D=0A> should help. =0D= =0A=0D=0AI added self.Update() to each frame on the update event, and that = fixed=0D=0Amy problem on OS X. I'm guessing that the wx.Timer events force = an=0D=0Aupdate=3F=0D=0A=0D=0A> I think you want to avoid the Loop method, a= s it can block other=0D=0A> widget events. I believe that what you want is = to replot the=0D=0A> figure when (a) the data has changed and (b) some mini= mum time=0D=0A> has elapsed since the last drawing. One approach is to use= a=0D=0A> timer to periodically check (this sets the minimun time) for new=0D= =0A> data, and redraw the plot when there's new data.=0D=0A=0D=0AI'm less b= othered about the minimum time, though I do like the idea of=0D=0Asetting u= p a timer in the monitor frame, and polling for a changed state=0D=0Ain the= object it's monitoring, and might change part of my design to=0D=0Aimpleme= nt that in the 'real' code.=0D=0A=0D=0A> Another approach is to trigger on = changes in the data, possibly=0D=0A> saving the timestamp when a redraw is = done so as to not draw too=0D=0A> often. Which method to use probably depe= nds on how easily it is=0D=0A> to detect and act upon changes to the data. = =20=0D=0A=0D=0AThis is what I'm doing in the full application (bar the time= stamp) at=0D=0Athe moment - it's under a 'data-push' model at the moment.=0D= =0A=0D=0A> Finally, you may also consider putting the data-intensive code i= n a separate=0D=0A> thread from the GUI.=0D=0A=0D=0AAh, threads... I'll st= ick to the self.Update() for now ;)=0D=0A=0D=0A> But I think the main issue= is to not try to redraw the plot 50=0D=0A> times per second. ;).=0D=0A=0D=0A= <grin> My algorithm coding isn't good enough for that to be an issue,=0D=0A= anyway. But I think the root of the cross-platform problem might lie=0D=0A= elsewhere, and the different steps I had to take on each OSs are=0D=0Apuzzl= ing me. On Windows I didn't need to add self.Update() calls, as=0D=0Aevery= thing worked first time. On Linux, the plot updated without resort=0D=0Ato= self.Update(), but the buttons didn't - and adding the self.Update()=0D=0A= calls only caused the buttons to appear blank, rather than not=0D=0Achange.= =2E.=20=0D=0A=0D=0AOn OS X, however, adding the self.Update() calls made it= run exactly how=0D=0AI wanted (and expected). I'm guessing that the wx.Ti= mer events are=0D=0Apropagating Update() calls to both frames within wx, wh= ile the other two=0D=0Amethods aren't. Except in Windows. Hmm... more re= ading ahead for me.=0D=0A=0D=0AStill, most importantly (for me) my problem = is solved, and I've learnt=0D=0Athings about wx events, and cross-platform = issues. Many thanks again=0D=0Afor your help, Matt - I'd have been flounde= ring much longer without it.=0D=0ANow I'll try to solve some of the non-mat= plotlib-related issues ;)=0D=0A=0D=0ACheers,=0D=0A=0D=0A--=20=0D=0ADr Leigh= ton Pritchard AMRSC=0D=0AD131, Plant-Pathogen Interactions, Scottish Crop R= esearch Institute=0D=0AInvergowrie, Dundee, Scotland, DD2 5DA, UK=0D=0AT: += 44 (0)1382 562731 x2405 F: +44 (0)1382 568578=0D=0AE: lp...@sc....u= k W: http://bioinf.scri.sari.ac.uk/lp=0D=0AGPG/PGP: FEFC205C E58BA41B ht= tp://www.keyserver.net =20=0D=0A(If the signature does not verif= y, please remove the SCRI disclaimer)=0D=0A_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ = _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _=0D=0A=0D=0ADISCLAIMER:=0D=0A=0D= =0AThis email is from the Scottish Crop Research Institute, but the views =0D= =0Aexpressed by the sender are not necessarily the views of SCRI and its =0D= =0Asubsidiaries. This email and any files transmitted with it are confiden= tial=20=0D=0Ato the intended recipient at the e-mail address to which it ha= s been=20=0D=0Aaddressed. It may not be disclosed or used by any other tha= n that addressee.=0D=0AIf you are not the intended recipient you are reques= ted to preserve this=20=0D=0Aconfidentiality and you must not use, disclose= , copy, print or rely on this=20=0D=0Ae-mail in any way. Please notify post= ma...@sc... quoting the=20=0D=0Aname of the sender and delete th= e email from your system.=0D=0A=0D=0AAlthough SCRI has taken reasonable pre= cautions to ensure no viruses are=20=0D=0Apresent in this email, neither th= e Institute nor the sender accepts any=20=0D=0Aresponsibility for any virus= es, and it is your responsibility to scan the email=20=0D=0Aand the attachm= ents (if any).=0D=0A |