I'm relatively new to matplotlib. Trying to place a colorbar in a figure. The 
code below, placed in a file and executed with python, draws 4 maps using 
basemap. I've been unable to get a colorbar to show up anywhere on the figure. 
Ideally I would like the option of placing a colorbar across the bottom, 
spanning across both bottom map panels.  Also would need the option of placing 
a colorbar either to the right of or below each map. Uncommenting the two lines 
under "Here make a colorbar" cause an error. I've used those commands when 
creating just one map using the figure command.

TIA,
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 *

alloptions, otherargs= getopt.getopt(sys.argv[1:],'ro:p:X:Y:v:t:l:u:n:') # note 
the : after o and p
proj='lam'

cmap = cm.get_cmap('jet', 10)    # 10 discrete colors

print "\nPlotting, please wait...maybe more than 10 seconds"
if proj=='lam': #Lambert Conformal
    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.)

xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
cax = axes([0.88, 0.1, 0.06, 0.81])  #  colorbar axes for map w/ graticule

############################################################################################
subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.15, 
hspace=0.11)
# Make the first map at upper left
sp = plt.subplot(2,2,1)

#  Here make a colorbar.
#cax = axes([0.88, 0.1, 0.06, 0.81])  #  colorbar axes for map w/ graticule
#colorbar(format='%3.1f', ticks=[-1.5, -1.2, -0.9, -0.6, -0.3, 0.0, 0.3, 0.6, 
0.9, 1.2, 1.5], cax=cax)

# draw coastlines and political boundaries.
m.drawcoastlines()
m.drawcountries()
m.drawstates()

#  Make the second map  
#########################################################################
sp = plt.subplot(2,2,2)
# draw coastlines and political boundaries.
m.drawcoastlines()
m.drawcountries()
m.drawstates()

#  Make the third map   
#########################################################################
sp = plt.subplot(2,2,3)
# draw coastlines and political boundaries.
m.drawcoastlines()
m.drawcountries()
m.drawstates()

#  Make the fourth map   
#########################################################################
sp = plt.subplot(2,2,4)
# draw coastlines and political boundaries.
m.drawcoastlines()
m.drawcountries()
m.drawstates()

plt.show()
plt.savefig("map.eps")
plt.clf()   # Clears the figure object
------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to