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
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
verbose=0 #verbose=2 says a bit more
import sys,getopt
from mpl_toolkits.basemap import Basemap, shiftgrid, cm
#from netCDF3 import Dataset as NetCDFFile
from mpl_toolkits.basemap import NetCDFFile
from pylab import *
import matplotlib.pyplot as plt
#fg = plt.figure(figsize=(10,8))
#adj = plt.subplots_adjust(hspace=0.4,wspace=0.4)
#sp = plt.subplot(2,2,1)
# Here set map title and the file containing gridded data to plot
thetitle='Map #1'
ncfile = NetCDFFile('simple_xy.nc', 'r') # Here's filename
startlon=-180 #default assumption for starting longitude
m = Basemap(llcrnrlon=-80.6,llcrnrlat=38.4,urcrnrlon=-66.0,urcrnrlat=47.7,\
resolution='l',area_thresh=1000.,projection='lcc',\
lat_1=65.,lon_0=-73.3)
xtxt=200000. #offset for text
ytxt=200000.
parallels = arange(38.,48.,2.)
meridians = arange(-80.,-64.,2.)
if verbose>1: print m.__doc__
xsize = rcParams['figure.figsize'][0]
fig=plt.figure(figsize=(xsize,m.aspect*xsize))
ax = fig.add_axes([0.07,0.00,0.86,1.0],axisbg='white')
axes(ax) # make the original axes current again
# draw coastlines and political boundaries.
m.drawcoastlines()
m.drawcountries()
m.drawstates()
if not thetitle:
title(thevar+extratext)
else:
title(thetitle)
#plt.show()
##########################################################################
# Example: http://physics.nmt.edu/~raymond/software/python_notes/paper004.html
sp = plt.subplot(2,2,1)
x = linspace(0,10,101)
y = exp(x)
l1 = plt.semilogy(x,y,color='m',linewidth=2)
sp = plt.subplot(2,2,2)
y = x**-1.67
l1 = plt.loglog(x,y)
sp = plt.subplot(2,2,3)
x = arange(1001)
y = mod(x,2.87)
l1 = plt.hist(y,color='r',rwidth = 0.8)
sp = plt.subplot(2,2,4)
l1 = plt.hist(y,bins=25,normed=True,cumulative=True,orientation='horizontal')
plt.show()
#plt.savefig('map.eps')
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.
------------------------------------------------------------------------------
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