Ordering contourf within a range

In plotting the figure in the below code, I need to set the colorbar and contourf scale to a specific value range (e.g., -100 to 100). When plotting similar items, I need to ensure the scale is the same across multiple images for comparison and overide the autoscaling. Any ideas? Seems like it should be something obvious, but I’ve been chasing my tail and coming up empty. I appreciate the help!

m = Basemap(resolution=‘c’,projection=‘cyl’,llcrnrlon=lon1,llcrnrlat=lat1,\

urcrnrlon=lon2,urcrnrlat=lat2)

x,y = np.meshgrid(lon, lat)

fig1=plt.figure()

CS = m.contour(x,y,narr_totcld_summer - wwmca_totcld_summer,15,linewidths=0.5,colors=‘k’)

CS = m.contourf(x,y,narr_totcld_summer - wwmca_totcld_summer,cmap=plt.cm.jet)

#CS = m.contourf(x,y,narr_totcld_summer - wwmca_totcld_summer,cmap=plt.cm.jet, clim=[-100,100]) #didn’t work…no error but no scaling

cbar = plt.colorbar(CS, shrink=0.7, format="%1.1f", spacing=‘proportional’,orientation=‘vertical’)

m.drawcoastlines()

m.drawmapboundary()

draw parallels and meridians.

parallels = np.arange(-90,90,5)

m.drawparallels(parallels,labels=[1,0,0,1])

meridians = np.arange(0,357.5,5)

m.drawmeridians(meridians,labels=[1,0,0,1])

plt.title(‘Figure title’)

plt.show()

···

Bruce W. Ford
Clear Science, Inc.

you mean something like that?

m.contourf(x, y, var, np.linspace(-100,100,33))

best regards

In addition to that (which would provide control over the contouring), one can create a Normalization object, and supply that to the contourf calls to make sure that the coloring is done consistently. Then, I recommend making the colorbar object directly with a cmap and the same normalization objects that you used for the contourf()'s. This example should be helpful:

http://matplotlib.sourceforge.net/examples/api/colorbar_only.html

Cheers!
Ben Root

···

On Fri, Aug 12, 2011 at 12:47 PM, Yoshi Rokuko <yoshi@…713…676…> wrote:

you mean something like that?

m.contourf(x, y, var, np.linspace(-100,100,33))

best regards

That’s exactly it! Thanks guys!

Bruce

···

Bruce W. Ford
Clear Science, Inc.
bruce@…2905…

http://www.ClearScienceInc.com
http://www.facebook.com/clearscience
http://www.twitter.com/ROVs_rule

Phone: (904) 796-8101
Fax: (904) 379-9704
8241 Parkridge Circle N.
Jacksonville, FL 32211
Skype: bruce.w.ford

On Fri, Aug 12, 2011 at 1:47 PM, Yoshi Rokuko <yoshi@…2559…76…> wrote:

you mean something like that?

m.contourf(x, y, var, np.linspace(-100,100,33))

best regards


FREE DOWNLOAD - uberSVN with Social Coding for Subversion.

Subversion made easy with a complete admin console. Easy

to use, easy to manage, easy to install, easy to extend.

Get a Free download of the new open ALM Subversion platform now.

http://p.sf.net/sfu/wandisco-dev2dev


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

    you mean something like that?

    m.contourf(x, y, var, np.linspace(-100,100,33))

    best regards

In addition to that (which would provide control over the contouring),
one can create a Normalization object, and supply that to the contourf
calls to make sure that the coloring is done consistently. Then, I

I think it is usually better to accept the default norm, and simply set the color boundaries using the levels kwarg or the equivalent forth argument as above.

recommend making the colorbar object directly with a cmap and the same
normalization objects that you used for the contourf()'s. This example
should be helpful:

I don't agree. It is simpler to pass the ContourSet object to the colorbar command or method. Colorbar knows about contourf and "just works" with it. See

http://matplotlib.sourceforge.net/examples/pylab_examples/contourf_demo.html

for basic contourf with colorbar, and

http://matplotlib.sourceforge.net/examples/pylab_examples/multi_image.html

for a colorbar with multiple images (contourf plots would work the same). The latter is more complex than is usually needed (it handles interactive changing of the colormap), but illustrates the use of a colorbar in a custom-made axes.

http://matplotlib.sourceforge.net/examples/api/colorbar_only.html

The colorbar_only example should be needed only *very* rarely, if ever.

Eric

···

On 08/12/2011 08:07 AM, Benjamin Root wrote:

On Fri, Aug 12, 2011 at 12:47 PM, Yoshi Rokuko <yoshi@…3676… > <mailto:yoshi@…3676…>> wrote:

Cheers!
Ben Root