On 12/30/2011 11:41 AM, Stephen Webb wrote:
> Hello all,
>
> I have a python module that requires making about 24 different kinds of
> plots, and to keep things tidy I put them all in different modules,
> which I then import.
>
> All the import calls are at the head of the top module. There is one
> plotting call inside a while loop, and it is returning blank plots saved
> in the proper location. Blank meaning no axes, so it is a totally empty
> .png file. After the loop, the first plot called is being saved, but all
> the subsequent plots are saving as blank. I begin every plotting module
> with matplotlib.pyplot.clf() and then write out the individual plotting
> commands.
>
> This worked fine when everything was in one gigantic module, but I am at
> a loss for why it has stopped working once I put everything into submodules.

One way or another, I think you are plotting in one figure, and then 
saving another (empty) figure.  This type of thing typically comes from 
mixing pyplot state-machine style with object style. It has happened to 
me. The problem is that pyplot commands create a new figure if they 
don't find an existing "current figure". The easiest way to solve this 
problem is to use only the minimal pyplot commands, and do everything 
else with explicit references to figures and axes.

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.plot([1,2,3])
fig.savefig("test.png")
plt.close(fig)


If you use the pattern above, then it is always clear where the plotting 
is going and what is being written out.  You are probably better off 
creating a figure when you are ready to plot in it, and closing it when 
finished, rather than trying to recycle it by clearing it. There will be 
very little difference in the time required.

Eric


>
> Thanks for your help,
>
> Stephen D. Webb
> Associate Research Scientist
> Tech-X Corporation
> http://www.txcorp.com
>
> e: sw...@txcorp.com
> 5621 Arapahoe Ave. Suite A
> Boulder, CO 80303 USA
>
>
>
> ------------------------------------------------------------------------------
> Write once. Port to many.
> Get the SDK and tools to simplify cross-platform app development. Create
> new or port existing apps to sell to consumers worldwide. Explore the
> Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
> http://p.sf.net/sfu/intel-appdev
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to