there is a matrix with numerical data (Index_Sver_total), you need to create a color scale on which a certain range of values ​​is associated with each color. Specifically: green corresponds to the range 1-300, blue 301-1000, yellow 1001-4000, red 4001-10000, brown> 10001. That is, it should be similar to this: enter image description here

Code:

nllcrnrlat=53.871 nurcrnrlat=61.869 nllcrnrlon=72.9 nurcrnrlon=90 clevs = [0,300,1000,4000,10000] ax = plt.subplot ax = Basemap(projection='cyl',llcrnrlat=nllcrnrlat,urcrnrlat=nurcrnrlat,llcrnrlon=nllcrnrlon,urcrnrlon=nurcrnrlon,resolution='h') ax.drawparallels(np.arange(nllcrnrlat,nurcrnrlat,0.186),labels=[True,False,False,False]) ax.drawmeridians(np.arange(nllcrnrlon,nurcrnrlon,0.225),labels=[False,False,False,True]) cs = ax.contourf(lons,lats,Index_Sver_total,clevs) ax.colorbar(cs) plt.title('Index Sverlova') plt.show() 

Only it is necessary to make by means of imshow (without interpolation). At the moment it turned out like this: enter image description here Code:

 nllcrnrlat=53.871 nurcrnrlat=61.869 nllcrnrlon=72.9 nurcrnrlon=90 clevs = [0,300,1000,4000,10000] ax = plt.subplot ax = Basemap(projection='cyl',llcrnrlat=nllcrnrlat,urcrnrlat=nurcrnrlat,llcrnrlon=nllcrnrlon,urcrnrlon=nurcrnrlon,resolution='h') ax.drawparallels(np.arange(nllcrnrlat,nurcrnrlat,0.186),labels=[True,False,False,False]) ax.drawmeridians(np.arange(nllcrnrlon,nurcrnrlon,0.225),labels=[False,False,False,True]) img = ax.imshow(Index_Sver_total,interpolation='none',cmap='jet') ax.colorbar(img) plt.title('Index Sverlova') plt.show() 

But this is not what is needed, because the values ​​in the matrix change at each iteration, and, accordingly, each time the image is displayed, the values ​​in the scale will jump, but the scale must be constant. It is necessary to build a scale similar to 1 picture. I read the matplotlib library documentation about imshow and colorbar, but without success. I would be grateful for your help.

  • I read three times the explanation of why this "not what is needed," but did not understand. - Enikeyschik February
  • What you do not understand in the explanation? I need to build a scale similar to that in 1 image, but using imshow, because in 1 image there is interpolation (and I don’t need it). - Ravsar
  • To fix the scale, do plt.clim(low, upper) . - Avernial
  • And how to set a range for each color as in 1 picture, only with the help of imshow? - Ravsar

1 answer 1

I figured out that the color scale can be built by setting the parameter cmap = matplotlib.colors.ListedColormap (['g', 'b', 'y', 'r', 'maroon']) in imshow. enter image description here But I still haven't figured out how to set a numeric range for each color ('g': 1-300, 'b': 301-1000, 'y': 1001-4000, 'r': 4001-10000, 'maroon': 10001 -infinity). plt.clim (low, upper) - sets only the boundaries of the scale, so this is not quite what you need.