python - Color scale - close but not close enough -
i'm trying produce plot uses same colorscale met office, can compare plots theirs. example of theirs @ here
my current closest effort here: here
i appreciate code messy - couldn't find way set color values above threshold (otherwise goes white),hence loop.
i upload netcdf file haven't got high enough rep this.
many, many in advance help.
my code plotting shown below;
from scientific.io.netcdf import netcdffile mpl_toolkits.basemap import basemap matplotlib import pyplot plt import numpy np myfile = netcdffile('era_dec_89-94.nc', 'r') lat = netcdffile('/home/james/documents/lat_lon_nc_files/latitudes_d02.nc','r') long = netcdffile('/home/james/documents/lat_lon_nc_files/longitudes_d02.nc','r') xlat = lat.variables['xlat'][:] xlong = long.variables['xlong'][:] era_data = myfile.variables['monthlyrain'][:] plot = np.zeros([1000,1730]) plot[:,:] = np.average(era_data[:,:,:],axis=0) m = basemap(projection='merc',resolution='f',llcrnrlat=49,llcrnrlon=-11,urcrnrlat=61,urcrnrlon=3) m.drawparallels(np.arange(-90., 91., 5.), labels=[1,0,0,0], fontsize=11) m.drawmeridians(np.arange(-180., 181., 5.), labels=[0,0,0,1], fontsize=11) m.drawcoastlines() x, y = m(xlong, xlat) in range(0,1729): j in range(0,999): if plot[j,i] >250: plot[j,i] = 250.001 if plot[j,i] < 40: plot[j,i] = 40 scale = [40,40.001,60,80,100,125,150,200,250, 250.001] cs = m.contourf(x,y,plot,scale, cmap='puor') cbar = m.colorbar(cs, ticks= [40.0005,50,70,90,112.5,137.5,175,225,250.0005]) cbar.set_ticklabels(['<40','40-60', '60-80', '80-100', '100-125', '125-150', '150-200', '200-250', '>250']) plt.title('some title') cbar.set_label('monthly average rainfall (mm)') print "finished" plt.show()
the first part (getting colors right) was answered. in order restrict values range have several options.
Comments
Post a Comment