Skip to content

Commit f26151b

Browse files
author
Jeff Whitaker
committed
use new colorbar method.
1 parent b10e4a3 commit f26151b

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

examples/plotmap.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@
2727
topodat,x,y = m.transform_scalar(topoin,lons,lats,nx,ny,returnxy=True)
2828
# create the figure.
2929
fig=plt.figure(figsize=(8,8))
30-
# add an axes, leaving room for colorbar on the right.
31-
ax = fig.add_axes([0.1,0.1,0.7,0.7])
30+
# add an axes.
31+
ax = fig.add_axes([0.1,0.1,0.8,0.8])
3232
# associate this axes with the Basemap instance.
3333
m.ax = ax
3434
# plot image over map with imshow.
3535
im = m.imshow(topodat,plt.cm.jet)
36-
# setup colorbar axes instance.
37-
pos = ax.get_position()
38-
l, b, w, h = pos.bounds
39-
cax = plt.axes([l+w+0.075, b, 0.05, h])
40-
plt.colorbar(im,cax=cax) # draw colorbar
36+
cb = m.colorbar(im,location='right',pad='10%') # draw colorbar
4137
# plot blue dot on boulder, colorado and label it as such.
4238
xpt,ypt = m(-104.237,40.125)
4339
m.plot([xpt],[ypt],'bo')

examples/simpletest_oo.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
fig = Figure()
2121
canvas = FigureCanvas(fig)
2222

23-
# create axes instance, leaving room for colorbar at bottom.
24-
ax = fig.add_axes([0.125,0.175,0.75,0.75])
23+
# create axes instance
24+
ax = fig.add_axes([0.1,0.1,0.8,0.8])
2525

2626
# create Basemap instance for Robinson projection.
2727
# set 'ax' keyword so pylab won't be imported.
@@ -40,11 +40,9 @@
4040
# add a title.
4141
ax.set_title('Robinson Projection')
4242

43-
# add a colorbar.
44-
pos = ax.get_position()
45-
l, b, w, h = pos.bounds
46-
cax = fig.add_axes([l, b-0.1, w, 0.03],frameon=False) # setup colorbar axes
47-
fig.colorbar(cs, cax=cax, orientation='horizontal',ticks=cs.levels[::3])
43+
# add a colorbar (must specify mappable and fig keywords, of pyplot will be
44+
# invoked) .
45+
cb=m.colorbar(mappable=cs,location='right',size='5%',pad='2%',ticks=cs.levels[::3],fig=fig)
4846

4947
# save image (width 800 pixels with dpi=100 and fig width 8 inches).
5048
canvas.print_figure('simpletest',dpi=100)

0 commit comments

Comments
 (0)