From: Benjamin R. <ben...@ou...> - 2012-10-16 16:15:32
|
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 |