Python: setting color constraints for pcolormesh basemap

Python newbie here. I am trying to set color constraints in basemap pcolormesh, same as

matplotlib.pyplot.clim(-1, 1)

      

will set the minimum color to -1 and the maximum to 1. My code looks like this:

llcrnrlat = numpy.amin(gridLatLon['lat'])-0.5
urcrnrlat = numpy.amax(gridLatLon['lat'])+0.5
llcrnrlon = numpy.amin(gridLatLon['lon'])-0.5
urcrnrlon = numpy.amax(gridLatLon['lon'])+0.5

m = Basemap(projection='cyl', llcrnrlat=llcrnrlat,urcrnrlat=urcrnrlat,\
        llcrnrlon=llcrnrlon,urcrnrlon=urcrnrlon,resolution='c')

y, x = m(gridLatLon['lat'], gridLatLon['lon'])

m.drawcoastlines()
m.drawcountries()
m.pcolormesh(x, y, efdata, latlon=True)

      

and it produces this , whereas I am looking for the colors to be between -1 and 1, which would produce something like this (which I used using clim (), but not in the basemap).

Any suggestions for improving the code are welcome.

Edit: gridLatLon

- a dictionary containing one field called lat

, which is an array of two-dimensional numbers in latitudes, and one field called lon

, an array of two-dimensional quanta of the corresponding longitudes. I am trying to plot efdata

, another two dimensional numpy array of the same size as the others.

+3


source to share


1 answer


Found:

m.pcolormesh(x, y, efdata, latlon=True, vmin=-1, vmax=1)

      



from here . However, suggestions are still welcome.

+1


source







All Articles