On Thu, Jan 12, 2012 at 4:32 PM, Michael Rawlins <rawlin...@yahoo.com>wrote:
> On 01/12/12 Ben Root wrote:
>
> On Thu, Jan 12, 2012 at 4:00 PM, Michael Rawlins <rawlin...@yahoo.com>wrote:
>
>
> On 01/12/12 Ben Root wrote:
>
> On Thu, Jan 12, 2012 at 2:20 PM, Michael Rawlins <rawlin...@yahoo.com>wrote:
>
>
> On 01/12/12 Ben Root wrote:
>
> Just a quick suggestion for cleaning up your code, please look into the
> argparse module to make command-line parsing so much easier to use.
> <http://docs.python.org/dev/library/argparse.html>
> http://docs.python.org/dev/library/argparse.html
>
> Ben Root
>
>
>
> Command line parsing? I'm new to python and matplotlib and was given this
> code by a colleague. I've managed to make simple modifications. Don't know
> enough yet to use the examples in the link you provide.
>
> I've simplified my code as much as possible. The first 50 lines make a
> map. The code below that makes a 4 panel graphic. Seems that plt.figure
> invokes a new plot window. But plt.semilogy, plt.loglog, and plt.hist do
> not, keeping the panels in a single window. This is what I need. Trying now
> to figure out how to transfer the fig=plt.figure line into the subplot
> section, without popping up a new window.
>
> Mike
>
>
>
> Ok, a quick crash course:
>
> A "figure" can hold one or more "axes" (or subplots). When using "plt",
> you can choose to make figures explicitly with the "fig = plt.figure()"
> command or not. The same is true for axes objects. If you call a command
> that needs a figure and/or an axes object to have been made and they don't
> exist, then they are made for you automatically. Otherwise, the most
> recently accessed figure/axes are assumed. This is why plt.hist(),
> plt.semilog() and others are not creating a new figure window if one
> already existed.
>
> Anyway, for your code, you do not want to bring in the plt.figure() call
> into the subploting section. The example you were given takes advantage of
> pyplot's implicit syntax (where it is implicitly assumed which axes/figure
> object you are using). However, I personally do not like that approach, and
> instead decided to show you an explicit style. I created a foobar()
> function that takes a blank figure object and other parameters, creates the
> four subplot axes and performs drawing on each of them. Note that the
> title is for the subplot, not for the figure. If you want a title for the
> figure above all the other subplots, use "fig.suptitle()". I then have a
> loop where a figure is created each time, the foobar() function acts on
> that figure, saved and then cleared before the next iteration.
>
> Note, I noticed you had "plt.show()" commented out before the call to
> "plt.savefig()". Usually, you will want savefig() to come *before* show()
> because closing the figure window will destroy the figure object, resulting
> in a blank figure to save if done afterwards.
>
> I hope this is helpful!
> Ben Root
>
>
>
>
> OK starting to make sense. Yes very helpful. I think what's you've set up
> might work, provided I can pass a filename for data into the function.
>
> At the moment I'm getting an error:
>
> NameError: name 'foobar' is not defined
>
> for the line with: foobar(fig, m, title)
>
> Mike
>
>
> My bad... I put the declaration of the foobar() function after it is
> called in the script. This isn't an issue if they are in separate scopes,
> but because "def foobar" is in the same scope as the call to it, it must
> have already been declared before it gets called. Just move that function
> to the area after all the imports.
>
> Ben Root
>
>
> Thanks for the help. Code throwing another error:
>
> Traceback (most recent call last):
> File "panels_testingNEW4.py", line 69, in <module>
> foobar(fig, m, title)
> File "panels_testingNEW4.py", line 23, in foobar
> title(title)
> TypeError: 'str' object is not callable
>
>
Oh, right, the creation of the "title" variable got rid of the existing
function. Just do "ax.set_title(title)" instead.
Ben Root
------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users