On Thursday, January 19, 2012, Michael Rawlins <rawlins02@yahoo.com> wrote:
>
>
> ________________________________
> From: Michael Rawlins <rawlins02@yahoo.com>
> To: Benjamin Root <ben.root@ou.edu>
> Cc: "matplotlib-users@lists.sourceforge.net" <matplotlib-users@lists.sourceforge.net>
> Sent: Wednesday, January 18, 2012 10:13 AM
> Subject: Re: [Matplotlib-users] placing colorbar when using subplot command
>
>
>
> ________________________________
> From: Benjamin Root <ben.root@ou.edu>
> To: Michael Rawlins <rawlins02@yahoo.com>
> Cc: "matplotlib-users@lists.sourceforge.net" <matplotlib-users@lists.sourceforge.net>
> Sent: Tuesday, January 17, 2012 2:02 PM
> Subject: Re: [Matplotlib-users] placing colorbar when using subplot command
>
>
> On Tue, Jan 17, 2012 at 12:37 PM, Michael Rawlins <rawlins02@yahoo.com> wrote:
>
>
> ________________________________
> From: Benjamin Root <ben.root@ou.edu>
> To: Michael Rawlins <rawlins02@yahoo.com>
> Cc: "matplotlib-users@lists.sourceforge.net" <matplotlib-users@lists.sourceforge.net>
> Sent: Tuesday, January 17, 2012 10:36 AM
> Subject: Re: [Matplotlib-users] placing colorbar when using subplot command
>
>
> On Tue, Jan 17, 2012 at 9:30 AM, Michael Rawlins <rawlins02@yahoo.com> wrote:
>
> 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
>
>
> Mike,
>
> Try using the axes_grid1 toolkit to produce your axes objects and to allocate enough room for colorbars.
>
> http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/index.html
>
> Cheers!
> Ben Root
>
> P.S. - a little history, there used to be an axes_grid toolkit, but has since been superseded by axes_grid1.
>
>
> Clicking on source code on that page produces an error. For several of the graphic on that page, dropping the code into a file and running also produces various errors. Being new to this software, having a specific example that I can run and then incorporate into my code would be a big help.
>
> Mike
>
>
>
> Mike,
>
> I do apologize for that.  We will have to get that fixed on the website (not sure why it is happening).  I have attached an example file for you to try.  Also, which version of matplotlib are you running?  Without the error message you are getting, it would be hard to tell you what is wrong (most likely it is a version issue).
>
> Ben Root
>
>
>
> Version 0.99.1.1 installed through Synaptic package manager on system running Ubuntu 10.04. I'd rather not attempt a fresh install from sources just yet.  Adding a colorbar alonside each map panel is possible. Anyone able to modify that code to make that work? I'm assuming it very simple for an experienced user.  Also, is it possible to add axes_grid1.py to my directory? If I want to get fancy in the future I will install version 1 and use axes_grid1.py.
>
> Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
> [GCC 4.4.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import matplotlib
>>>> matplotlib.__version__
> '0.99.1.1'
>>>>
>
>
>
>
> Forum:
>
> Still unable to get a colorbar alongside the panels in this simple example.  One last request for assistance. Thanks.
>
> Mike
>
> 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
>
> cmap = cm.get_cmap('jet', 10)    # 10 discrete colors
>
> 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))
>
> ############################################################################################
> subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0.15, hspace=0.11)
> # Make the first map
> plt.subplot(1,2,1)
>
> # draw coastlines and political boundaries.
> m.drawcoastlines()
> m.drawcountries()
> m.drawstates()
>
> #  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)
> #colorbar(cax=cax)
>
> #  Make the second map  #########################################################################
> plt.subplot(1,2,2)
> # 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
>
>
>

I recommend upgrading to v1.1.0. There are some PPAs out there that has a more recent version of mpl available as a package. Or you can install from source.  Instructions for doing that is in the FAQ.

Ben Root