Skip to content Skip to sidebar Skip to footer

Color Scale - Close But Not Close Enough

I'm trying to produce a plot which uses the same colorscale as the Met Office, so I can easily compare my plots to theirs. An example of theirs is at Here My current closest effort

Solution 1:

If the issue is simply the colormap, you can pick the RGB components of the colors off your screen and turn them into a ListedColormap, mapped to the boundaries of the rainfall in the chart you give as an example. For example,

bounds = [0, 40, 60, 80, 100, 125, 150, 200, 250, 1000]
rgblist = [(51,0,0), (102,51,0), (153,102,51), (204,153,102), (255, 255, 255),
           (204,204,255), (153,153,255), (51,102,255), (0,0,153)]
clist = [[c/255 for  c in rgb] for rgb in rgblist]

from matplotlib import colors
cmap = colors.ListedColormap(clist)
norm = colors.BoundaryNorm(bounds, cmap.N)

ax.imshow(arr, cmap=cmap, norm=norm)
plt.show()

Solution 2:

The first part (getting the colors right) was already answered. In order to restrict the values to a certain range you have several options.

  • Use cmap.set_over and cmap.set_under to set out-of-bounds colors, as described here

  • use np.clip instead of the loop to restrict the values to a certian range:

    plot = np.clip(plot, 40, 250)

Post a Comment for "Color Scale - Close But Not Close Enough"