I use the
:balance colorscheme with the ideally zero as white at the centre of
Colorbar. The highest value is red and the lowest value is blue. If I have a range (-4.725205, 28.010359), I get around 10 at the centre of
Colorbar, but I need to zero is still in the centre and everything highest or lowest will be interpolated to the red or blue. How can I fix the centre of
Colorbar to zero?
The left image is an example of
colorrange = (-4.725205, 28.010359) and the centre is calculated as 11,642577, what is I don’t want.
The right image is example with zero in the centre, but it’s not fixed by programmer, it’s only calculated as (-17.564026, 22.240145) => 22.240145 - (-17.564026) = 39,804171 => 39,804171 / 2 = 19,9020855 => The centre is 2,3380595.
You have to make the colorrange symmetric:
data = randn(30, 30) .+ 1
f, ax, hm = heatmap(data,
colormap = :balance,
colorrange = (-1, 1) .* maximum(abs, data))
Colorbar(f[1, 2], hm)
It’s not precisely what I talking about, but it works. The main disadvantage is when the changes in values are too small. It makes the
colorrange so huge and can hide these small changes in values.
The first image is original.
The second image is after applied own calculation of the range.
On the other side, the symmetry is so good. I have the three scenarios with values. Only negative, only positive and combined. The zero is the common point for each of them.
if hm.colorrange >= 0
hm.colorrange = (0, 1) .* maximum(abs, hm.colorrange)
hm.colormap = :amp
if hm.colorrange > 0
hm.colorrange = (-1, 1) .* maximum(abs, hm.colorrange)
hm.colormap = :balance
hm.colorrange = (-1, 0) .* maximum(abs, hm.colorrange)
hm.colormap = :ice
println(hm.colorrange, ", ", hm.colorrange)
Ok that is a different problem, yes if you need to have zero in your colormap and don’t use any nonlinear scale, you will have hard to discriminate values if they are far away from zero and close together.
Why not? I can use a nonlinear scale.
Zeros = white color
Maximal values = red color
Minimal (only negative) values = blue color
Values between -100 and 0 or 0 and 100 can be nonlinearly scaled.
You see it here:
The first one has zero as white, but the second has 5 as white and the last one has 30 as white. These plots must be comparable with each other !!!
Here is the own scale by