2

I have plotted some data using matplotlib's imshow. I have also managed to combine three different colormaps for the plot (see figure), but I want the greens to go from 0-1000, the yellow/orange to go from 1000-1600 and reds from 1600 and up. It's almost correct out of the box, but not entirely. Anyone know how I can accomplish this?

colors1 = plt.cm.Greens_r(np.linspace(0, 0.4, 256))
colors2 = plt.cm.Oranges(np.linspace(0.1, 0.5, 256))
colors3 = plt.cm.Reds(np.linspace(0.6, 1, 256))

cmap = np.vstack((colors1, colors2, colors3))

cmap_test = colors.LinearSegmentedColormap.from_list('colormap', cmap)

fig, ax = plt.subplots()
plt.imshow(z, origin='upper', cmap=cmap_test, interpolation='none', extent=[0,25,5,-20])
cbar = plt.colorbar()
ax.grid(linestyle='-')
plt.show()

enter image description here

joddm
  • 589
  • 1
  • 6
  • 18
  • You probably want to sample each of the color maps from [0, 1], but vary the number of points you sample them with before you stack them. – tacaswell Jan 29 '17 at 04:41
  • Thanks! Some math and it did the trick @tacaswell :) – joddm Jan 29 '17 at 10:42
  • [Python equivalent for Matlab's Demcmap](http://stackoverflow.com/questions/40895021/python-equivalent-for-matlabs-demcmap-elevation-appropriate-colormap), [Matplotlib imshow - 'speed up' colour change in certain value ranges](http://stackoverflow.com/questions/40302485/matplotlib-imshow-speed-up-colour-change-in-certain-value-ranges), [How to change colorbar's color (in some particular value interval)?](http://stackoverflow.com/questions/41806285/how-to-change-colorbars-color-in-some-particular-value-interval) and links therein. – ImportanceOfBeingErnest Jan 29 '17 at 12:38

0 Answers0