Different colors regions for different heatmaps


Hello internet

Basically I’m doing are simple heatmaps with different color limits as in these examples:

using Plots
h1 = heatmap(1:10, 1:15, rand(15,10), clim=(0,0.5))
h2 = heatmap(1:10, 1:15, rand(15,10), clim=(0.5,1))
plot(h1,h2, size=(800,400))

But look at the color scheme. It begins from dark to bright again at each new figure.

I would like that in “half of the dark spectra of colors” to be used in figure at left, and “half of the bright” color at the figure of the right. This example has only 2 divisions, and I’m looking for a general case.

I don’t know the proper words to ask for google/discourse search, but if someone has the answer for this problem in other package I’m open mind.


The best approach is to set the color limits for the color bar. clim = (0,1)


Ah, I see what you mean. That’s not how it’s intended to be used. But you can create your own gradient by chopping the inbuilt one in halves:

magma = cgrad(:magma).colors
c1 = cgrad(magma[1:15])
c2 = cgrad(magma[16:end])
h1 = heatmap(1:10, 1:15, rand(15,10), clim=(0,0.5), c = c1)
h2 = heatmap(1:10, 1:15, rand(15,10), clim=(0.5,1), c = c2)
plot(h1,h2, size=(800,400))


Now that I see your solution, I had a good guess of how to solve my problem, but I was missing the .colors in cgrad()