bbox of map

hi all,

i'm trying to get the bounding box of a map plotted with basemap to place a
colorbar. in this reduced example from the example directory of basemap, the
colorbar is set to the hight of the axes of the plot.

from mpl_toolkits.basemap import Basemap, shiftgrid
import numpy as np
import matplotlib.pyplot as plt

topoin = np.loadtxt('etopo20data.gz')
lons = np.loadtxt('etopo20lons.gz')
lats = np.loadtxt('etopo20lats.gz')

topoin,lons = shiftgrid(180.,topoin,lons,start=False)

m = Basemap(llcrnrlon=-57,llcrnrlat=37,urcrnrlon=-3,urcrnrlat=60,
            resolution='i',projection='tmerc',lon_0=-41,lat_0=45)
# transform to nx x ny regularly spaced native projection grid
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat,x,y = m.transform_scalar(topoin,lons,lats,nx,ny,returnxy=True)
# create the figure.
fig=plt.figure(figsize=(8,8))
# add an axes, leaving room for colorbar on the right.
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# associate this axes with the Basemap instance.
m.ax = ax
# plot image over map with imshow.
im = m.imshow(topodat,plt.cm.jet)
# setup colorbar axes instance.
pos = ax.get_position()
l, b, w, h = pos.bounds
cax = plt.axes([l+w+0.075, b, 0.05, h])
plt.colorbar(im,cax=cax) # draw colorbar
# plot blue dot on boulder, colorado and label it as such.
plt.show()

what i'm interested in is the bounding box of m, the real plotting area, so
i can scale the colorbar axes to that height or width.

is there a way to get this?

thanks in advance

mario

···

--
View this message in context: http://old.nabble.com/bbox-of-map-tp31974326p31974326.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

i'm trying to get the bounding box of a map plotted with basemap to place a
colorbar. in this reduced example from the example directory of basemap, the
colorbar is set to the hight of the axes of the plot.

...

what i'm interested in is the bounding box of m, the real plotting area, so
i can scale the colorbar axes to that height or width.

I don't have time to find the Basemap example data files and run your
example, but I normally do it like this (which works fine for me -
it's not clear what problem you're seeing?):

    # create new figure
    fig = plt.figure()
    ax = fig.add_axes(...)

    curr_map = Basemap(..., ax=ax, ...)

    im = curr_map.imshow(...)

    # setup colorbar axes and draw colorbar
    bbox = ax.get_position()
    l,b,w,h = bbox.bounds
    cax = fig.add_axes([l+w+0.05, b, 0.05, h],frameon=False)
    fig.colorbar(im, cax=cax)

Maybe using the pyplot functions to add the colorbar axes and plot the
colorbar is causing some side-effects you don't expect?

Cheers,
Scott

···

On 1 July 2011 16:52, marz_cyclone <mech@...2927...> wrote: