Hi,
I am using Basemap to create a grid of 12 images of the world (months of
the year), but I want to have a single colorbar underneath the plots. I
have managed this successfully but I can't manage to shrink the colorbar
width. Currently it extends the entire width of the plotting window,
whereas I'd prefer it to be say extend 80% of the plotting window. I've
tried combining what I have with the shrink argument to colorbar but this
doesn't work. Does anyone know how I can achieve this?
Code:
import numpy as np
import matplotlib.pyplot as plt
import sys
import matplotlib.colors as colors
from mpl_toolkits.basemap import Basemap
from mpl_toolkits.axes_grid1 import AxesGrid
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct',\
'Nov','Dec']
fig = plt.figure(figsize=(14, 10))
grid = AxesGrid(fig, [0.05,0.05,0.9,0.9], nrows_ncols=(4,3), axes_pad=0.1,
cbar_mode='single', cbar_pad=0.4, cbar_size="7%",
cbar_location='bottom', share_all=True)
m = Basemap(projection='cyl', llcrnrlon=-179.5, llcrnrlat=-59.5, \
urcrnrlon=179.5, urcrnrlat=89.5, resolution='c')
for i, month in enumerate(months):
ax = grid[i]
m.ax = ax
m.drawcoastlines(linewidth=0.1, color='k')
m.drawcountries(linewidth=0.1, color='k')
if i == 0 or i == 3 or i == 6 or i == 9:
m.drawparallels(np.array([-90.0,-60.0,-30.0,0.0,30.0,60.0,90.0]),
labels=[1,0,0,1], fontsize=10, rotation=0,
linewidth=0.2, dashes=[2,2])
else:
m.drawparallels(np.array([-90.0,-60.0,-30.0,0.0,30.0,60.0,90.0]),
labels=[0,0,0,0], fontsize=10, rotation=0,
linewidth=0.2, dashes=[2,2])
if i >= 9:
m.drawmeridians(np.array([-180.0,-120.0,-60.0,0.0,60.0,120.0,180.0]),
labels=[0,0,0,1], fontsize=10, rotation=00,
linewidth=0.2, dashes=[2,2])
else:
m.drawmeridians(np.array([-180.0,-120.0,-60.0,0.0,60.0,120.0,180.0]),
labels=[0,0,0,0], fontsize=10, rotation=00,
linewidth=0.2, dashes=[2,2])
diff = np.random.rand(150,360)
image = m.imshow(diff, cmap=plt.cm.jet, interpolation='nearest')
textstr='%s' % (month)
props = dict(boxstyle='round', facecolor='white', alpha=1.0, ec="white")
ax.text(0.03, 0.1, textstr, transform=ax.transAxes, fontsize=8,
verticalalignment='top', bbox=props)
cbar = fig.colorbar(image, cax=grid.cbar_axes[0], orientation='horizontal')
plt.show()
Thanks,
Martin
*Dr. Martin De Kauwe*
*Research Fellow*
Department of Biological Sciences
E8C Building Room 205
Macquarie University
NSW 2109 Australia
T: +61 2 9850 9256
M: + 61 478 096 086
mdeka...@gmail.com
CRICOS Provider Number 00002J
Please consider the environment before printing this email.
This email (including all attachments) is confidential. It may be subject
to legal professional privilege and/or protected by copyright. If you
receive it in error do not use it or disclose it, notify the sender
immediately, delete it from your system and destroy any copies. The
University does not guarantee that any email or attachment is secure or
free from viruses or other defects. The University is not responsible for
emails that are personal or unrelated to the University’s functions.
------------------------------------------------------------------------------
Time is money. Stop wasting it! Get your web API in 5 minutes.
www.restlet.com/download
http://p.sf.net/sfu/restlet
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users