Skip to content

Commit b10e4a3

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

File tree

1 file changed

+20
-113
lines changed

1 file changed

+20
-113
lines changed

examples/test.py

Lines changed: 20 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@
2929
ax = fig.add_axes([0.1,0.1,0.7,0.7])
3030
# plot image over map.
3131
im = m.imshow(topoin,plt.cm.jet)
32-
# get axes position, add colorbar axes to right of this.
33-
pos = ax.get_position()
34-
l, b, w, h = pos.bounds
35-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
36-
plt.colorbar(cax=cax) # draw colorbar
37-
plt.axes(ax) # make the original axes current again
32+
m.colorbar() # draw colorbar
3833
m.drawcoastlines()
3934
#m.drawcountries()
4035
#m.drawstates()
@@ -128,13 +123,7 @@
128123
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
129124
# plot image over map.
130125
im = m.imshow(topodat,plt.cm.jet)
131-
# get current axis instance.
132-
ax = plt.gca()
133-
pos = ax.get_position()
134-
l, b, w, h = pos.bounds
135-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
136-
plt.colorbar(cax=cax) # draw colorbar
137-
plt.axes(ax) # make the original axes current again
126+
m.colorbar() # draw colorbar
138127
m.drawcoastlines()
139128
# draw parallels
140129
delat = 2.
@@ -160,13 +149,7 @@
160149
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
161150
# plot image over map.
162151
im = m.imshow(topodat,plt.cm.jet)
163-
# get current axis instance.
164-
ax = plt.gca()
165-
pos = ax.get_position()
166-
l, b, w, h = pos.bounds
167-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
168-
plt.colorbar(cax=cax) # draw colorbar
169-
plt.axes(ax) # make the original axes current again
152+
m.colorbar() # draw colorbar
170153
m.drawcoastlines()
171154
m.drawcountries()
172155
# draw parallels
@@ -193,13 +176,7 @@
193176
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
194177
# plot image over map.
195178
im = m.imshow(topodat,plt.cm.jet)
196-
# get current axis instance.
197-
ax = plt.gca()
198-
pos = ax.get_position()
199-
l, b, w, h = pos.bounds
200-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
201-
plt.colorbar(cax=cax) # draw colorbar
202-
plt.axes(ax) # make the original axes current again
179+
m.colorbar() # draw colorbar
203180
m.drawcoastlines()
204181
# draw parallels
205182
delat = 20.
@@ -224,13 +201,7 @@
224201
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
225202
# plot image over map.
226203
im = m.imshow(topodat,plt.cm.jet)
227-
# get current axis instance.
228-
ax = plt.gca()
229-
pos = ax.get_position()
230-
l, b, w, h = pos.bounds
231-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
232-
plt.colorbar(cax=cax) # draw colorbar
233-
plt.axes(ax) # make the original axes current again
204+
m.colorbar() # draw colorbar
234205
m.drawcoastlines()
235206
m.drawcountries()
236207
m.drawstates()
@@ -254,13 +225,7 @@
254225
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
255226
# plot image over map.
256227
im = m.imshow(topodat,plt.cm.jet)
257-
# get current axis instance.
258-
ax = plt.gca()
259-
pos = ax.get_position()
260-
l, b, w, h = pos.bounds
261-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
262-
plt.colorbar(cax=cax) # draw colorbar
263-
plt.axes(ax) # make the original axes current again
228+
m.colorbar() # draw colorbar
264229
m.drawcoastlines()
265230
m.drawcountries()
266231
# draw parallels
@@ -285,13 +250,8 @@
285250
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
286251
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
287252
ax = fig.add_axes([0.1,0.1,0.7,0.7])
288-
# plot image over map.
289253
im = m.imshow(topodat,plt.cm.jet)
290-
pos = ax.get_position()
291-
l, b, w, h = pos.bounds
292-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
293-
plt.colorbar(cax=cax) # draw colorbar
294-
plt.axes(ax) # make the original axes current again
254+
m.colorbar() # draw colorbar
295255
m.drawcoastlines()
296256
m.drawcountries()
297257
m.drawstates()
@@ -318,13 +278,8 @@
318278
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
319279
topodat = m.transform_scalar(topoin,lons,lats,nx,ny)
320280
ax = fig.add_axes([0.1,0.1,0.7,0.7])
321-
# plot image over map.
322281
im = m.imshow(topodat,plt.cm.jet)
323-
pos = ax.get_position()
324-
l, b, w, h = pos.bounds
325-
cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
326-
plt.colorbar(cax=cax) # draw colorbar
327-
plt.axes(ax) # make the original axes current again
282+
m.colorbar(pad='10%') # draw colorbar
328283
m.drawcoastlines()
329284
m.drawcountries()
330285
m.drawstates()
@@ -355,11 +310,7 @@
355310
# plot image over map.
356311
im = m.imshow(topodat,plt.cm.jet)
357312
im.set_clim(-4000.,3000.) # adjust range of colors.
358-
pos = ax.get_position()
359-
l, b, w, h = pos.bounds
360-
cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
361-
plt.colorbar(cax=cax) # draw colorbar
362-
plt.axes(ax) # make the original axes current again
313+
m.colorbar(pad='10%') # draw colorbar
363314
m.drawcoastlines()
364315
m.drawcountries()
365316
# draw parallels
@@ -390,11 +341,7 @@
390341
ax = fig.add_axes([0.1,0.1,0.7,0.7])
391342
# plot image over map.
392343
im = m.imshow(topodat,plt.cm.jet)
393-
pos = ax.get_position()
394-
l, b, w, h = pos.bounds
395-
cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
396-
plt.colorbar(cax=cax) # draw colorbar
397-
plt.axes(ax) # make the original axes current again
344+
m.colorbar(pad='12%') # draw colorbar
398345
m.drawcoastlines()
399346
m.drawcountries()
400347
#m.fillcontinents()
@@ -421,11 +368,7 @@
421368
ax = fig.add_axes([0.1,0.1,0.7,0.7])
422369
# plot image over map.
423370
im = m.imshow(topodat,plt.cm.jet)
424-
pos = ax.get_position()
425-
l, b, w, h = pos.bounds
426-
cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
427-
plt.colorbar(cax=cax) # draw colorbar
428-
plt.axes(ax) # make the original axes current again
371+
m.colorbar(pad='12%') # draw colorbar
429372
m.drawcoastlines()
430373
m.drawcountries()
431374
m.drawstates()
@@ -453,11 +396,7 @@
453396
ax = fig.add_axes([0.1,0.1,0.7,0.7])
454397
# plot image over map.
455398
im = m.imshow(topodat,plt.cm.jet)
456-
pos = ax.get_position()
457-
l, b, w, h = pos.bounds
458-
cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
459-
plt.colorbar(cax=cax) # draw colorbar
460-
plt.axes(ax) # make the original axes current again
399+
m.colorbar(pad='12%') # draw colorbar
461400
m.drawcoastlines()
462401
m.drawcountries()
463402
m.drawstates()
@@ -494,11 +433,7 @@
494433
# and values outside projection limb would be handled transparently
495434
# - see contour_demo.py)
496435
im = m.imshow(topo,palette,norm=colors.normalize(clip=False))
497-
pos = ax.get_position()
498-
l, b, w, h = pos.bounds
499-
cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
500-
plt.colorbar(cax=cax) # draw colorbar
501-
plt.axes(ax) # make the original axes current again
436+
m.colorbar() # draw colorbar
502437
# draw coastlines and political boundaries.
503438
m.drawcoastlines()
504439
# draw parallels and meridians (labelling is
@@ -535,11 +470,7 @@
535470
# and values outside projection limb would be handled transparently
536471
# - see contour_demo.py)
537472
im = m.imshow(topo,palette,norm=colors.normalize(clip=False))
538-
pos = ax.get_position()
539-
l, b, w, h = pos.bounds
540-
cax = plt.axes([l+w+0.075, b, 0.05, h]) # setup colorbar axes.
541-
plt.colorbar(cax=cax) # draw colorbar
542-
plt.axes(ax) # make the original axes current again
473+
m.colorbar() # draw colorbar
543474
# draw coastlines and political boundaries.
544475
m.drawcoastlines()
545476
# draw parallels and meridians (labelling is
@@ -563,11 +494,7 @@
563494
# plot image over map with pcolormesh.
564495
x,y = m(*np.meshgrid(lonsin,latsin))
565496
p = m.pcolormesh(x,y,topodatin,shading='flat')
566-
pos = ax.get_position()
567-
l, b, w, h = pos.bounds
568-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
569-
plt.colorbar(cax=cax) # draw colorbar
570-
plt.axes(ax) # make the original axes current again
497+
m.colorbar(location='bottom') # draw colorbar
571498
# draw coastlines and political boundaries.
572499
m.drawcoastlines()
573500
# draw parallels and meridians
@@ -590,11 +517,7 @@
590517
# plot image over map with pcolormesh.
591518
x,y = m(*np.meshgrid(lonsin,latsin))
592519
p = m.pcolormesh(x,y,topodatin,shading='flat')
593-
pos = ax.get_position()
594-
l, b, w, h = pos.bounds
595-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
596-
plt.colorbar(cax=cax) # draw colorbar
597-
plt.axes(ax) # make the original axes current again
520+
m.colorbar(location='bottom') # draw colorbar
598521
# draw coastlines and political boundaries.
599522
m.drawcoastlines()
600523
# draw parallels and meridians
@@ -617,11 +540,7 @@
617540
# plot image over map with pcolormesh.
618541
x,y = m(*np.meshgrid(lonsin,latsin))
619542
p = m.pcolormesh(x,y,topodatin,shading='flat')
620-
pos = ax.get_position()
621-
l, b, w, h = pos.bounds
622-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
623-
plt.colorbar(cax=cax) # draw colorbar
624-
plt.axes(ax) # make the original axes current again
543+
m.colorbar(location='bottom') # draw colorbar
625544
# draw coastlines and political boundaries.
626545
m.drawcoastlines()
627546
# draw parallels and meridians
@@ -644,11 +563,7 @@
644563
# plot image over map with pcolormesh.
645564
x,y = m(*np.meshgrid(lonsin,latsin))
646565
p = m.pcolormesh(x,y,topodatin,shading='flat')
647-
pos = ax.get_position()
648-
l, b, w, h = pos.bounds
649-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
650-
plt.colorbar(cax=cax) # draw colorbar
651-
plt.axes(ax) # make the original axes current again
566+
m.colorbar(location='bottom') # draw colorbar
652567
# draw coastlines and political boundaries.
653568
m.drawcoastlines()
654569
# draw parallels and meridians
@@ -671,11 +586,7 @@
671586
# plot image over map with pcolormesh.
672587
x,y = m(*np.meshgrid(lonsin,latsin))
673588
p = m.pcolormesh(x,y,topodatin,shading='flat')
674-
pos = ax.get_position()
675-
l, b, w, h = pos.bounds
676-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
677-
plt.colorbar(cax=cax) # draw colorbar
678-
plt.axes(ax) # make the original axes current again
589+
m.colorbar(location='bottom') # draw colorbar
679590
# draw coastlines and political boundaries.
680591
m.drawcoastlines()
681592
# draw parallels and meridians
@@ -697,11 +608,7 @@
697608
# plot image over map with pcolormesh.
698609
x,y = m(*np.meshgrid(lonsin,latsin))
699610
p = m.pcolormesh(x,y,topodatin,shading='flat')
700-
pos = ax.get_position()
701-
l, b, w, h = pos.bounds
702-
cax = plt.axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
703-
plt.colorbar(cax=cax) # draw colorbar
704-
plt.axes(ax) # make the original axes current again
611+
m.colorbar() # draw colorbar
705612
# draw coastlines and political boundaries.
706613
m.drawcoastlines()
707614
# draw parallels and meridians

0 commit comments

Comments
 (0)