From: John H. <jdh...@ac...> - 2004-01-08 18:04:36
|
>>>>> "Flavio" == Flavio C Coelho <fcc...@fi...> writes: Flavio> Hi, I have a problem with matplotlib: Flavio> My program is an interective simulator which needs to Flavio> re-plot results multiple times at the users request. Flavio> But after I issue show() I cannot generate other plots. Flavio> what can I do to circumvent this? If you are using matplotlib in an application, as it sounds like you are, you don't need to call show at all. You control the GUI mainloop yourself. See, for example, examples/embedding_in_gtk2.py or examples/embedding_in_wx.py. Do the application users need to use the matlab interface plotting commands themselves, or are they simply interacting with the plots using widgets you provide? If the latter, I suggest not using the matlab interface at all, and importing Figure from backends.backend_gtk or backends.backend_wx. and Subplot from axes and controlling the plots using the object oriented API. All of the matlab plotting commands are simply thin wrappers to the Axes API (hist, psd, scatter, etc... are all accessible from the axes instance) Eg, subplot(111) plot(t,s) xlabel('hi mom') set(gca(), 'xlim', [0,10]) is fig = Figure(figsize=(5,4), dpi=100) ax = Subplot(f, 111) ax.plot(t,s) ax.set_xlabel('hi mom') ax.set_xlim([0,10]) You can force a redraw of the figure by doing fig.draw() The moral of the story: don't call show for applications; that is for python batch scripts. Will this work for you? Of course if you have a shell and you want to allow your users to interact with the plot using the matlab interface, you'll need a different approach. Something along the lines of examples/interactive2.py, which is an interactive shell for pygtk. I haven't worked with custom shells for wx, but interactive control of matplotlib figures works in PyCrust with the CVS version of matplotlib. Make sure you are using the CVS version of matplotlib as a number of critical bugs in the WX backend that affect interactive use have been fixed since the 0.40 release. Note the API for working interactively has changed. You now do import matplotlib matplotlib.use('WX') matplotlib.interactive(True) Ditto for GTK. Here's a snapshot of the latest version in case your CVS mirrors are behind: http://nitace.bsd.uchicago.edu:8080/files/share/matplotlib-0.41c.tar.gz Hope this helps! John Hunter |