|
From: hari j. <ha...@gm...> - 2012-10-17 17:54:14
|
Thanks Benjamin, Sterling and Damon for your prompt help However I am still not able to achieve what I wanted . I can get the headless script to work just great where it saves all the figures and I can view them after the script is done running. But somehow when I try the figure number method that Sterling suggested , along with the axis clear and redraw method (Damon) , or the decouple and clear and then plot method (Benjamin Root) : I get the plot just spinning with a blue circle on Windows 7 and the script just chugs merrily along. I think part of the problem was that I was wrong in the way I stated my application. Each of the 384 data processing steps takes a few seconds..and not a minute as I had indicated. I tried with both ion() and ioff() and giving the figure a number , which stays constant and clearing the axis everytime before plotting. But I get a spiining blue circle in Windows. I will try and cookup a test case , and send to the list , to reproduce what I am seeing. it may still be that I am calling pylab , pyplot incorrectly and hence not getting the continuously changing figure that your suggestions should give me. hari Using plt.ion() or plt.ioff() causes a spinning blue-ball on windows..while the rest of the script continues. If I use the figure number trick. I get the first figure displayed. On Tue, Oct 16, 2012 at 12:15 PM, Benjamin Root <ben...@ou...> wrote: > > > On Tue, Oct 16, 2012 at 11:25 AM, hari jayaram <ha...@gm...> wrote: > >> Hi >> I am a relative newbie to matplotlib. >> >> I have a python script that handles a dataset that comprises 384 sets of >> data. >> >> At the present moment , I read in a set of data - process it - and the >> create a figure using code shown below. >> I am using windows with the default backend ( I think I set it to wx). >> >> When I run the program, figure after figure shows up..the program >> continues from well to well plotting the figure. I can close the figure >> window using the X on the right -hand side..while the program chugs along. >> >> Is there a way to just recycle the figure object , so that the plot shows >> up for a brief second and refreshes when the next calculation is complete. >> Each process_data function , takes a few minutes. >> >> Alternatively I just want to close the figure object I show after a brief >> lag. I am OK if that happens instantaneously..but I dont know how >> to achieve this. >> Do I have to use the matplotlib.Figure object to achieve this >> functionality >> >> Thanks >> Hari >> >> >> > Hari, > > To recycle the figure, try the following: > > > > import matplotlib.pyplot as plt > > def do_my_plot(par1, par2, well_id): > processed_data_object = processed_dict[well_id] > # Plot all the data > par1.plot(processed_data_object.raw_x,processed_data_object.raw_y). > par2.plot(.... > # finally > plt.show() > # I tried fig.clf() > > > def plot_and_process_data(): > plt.ion() # Turn on interactive mode > fig = plt.figure(figsize=(7,7) > ax = fig.add_subplot(1,1,1) > par1 =ax.twinx() > par2 = ax.twinx() > > for well_id in list_of_384_well_ids: > par1.cla() > par2.cla() > process_data(well_id) > do_my_plot(par1, par2, well_id) > > Note, this is completely untested, but it would be how I would go about it > at first. The "plt.ion()" turns on interactive mode to allow your code to > continue running even after the plot window appears (but does not end until > the last window is closed.). Of course, another approach would simply be > to do "fig.savefig()" after every update to the figure and never use show() > and ion() (essentially, a non-interactive head-less script). > > Hopefully, this helps. > Ben Root > > |