How to control the center color of diverging colorschemes
briochemc opened this issue · 2 comments
I would like to be able to slightly modify diverging color schemes that have a "center" color that is not exactly white in such a way that said center becomes exactly white. I can think of different ways to do it manually, like below (note the slight difference in the middle):
done via:
# ColorSchemes.RdBu but with a true white
reds = ColorSchemes.RdBu[1:end÷2]
blues = ColorSchemes.RdBu[end÷2+2:end]
colormap = ColorScheme(reds) * ColorScheme([colorant"white"]) * ColorScheme(blues)
but I'm sure I'm not doing it wrong, so I'm fishing for the correct way to do that thing above.
Hi! I don't have any insight in any "correct" way of working with colorschemes - perhaps there are colour specialists who have better insight, or perhaps there are best practices current in other language's color libraries - I wouldn't know myself.
As you say, it doesn't seem to difficult to modify them manually:
using ColorSchemes, Colors
cs = deepcopy(ColorSchemes.RdBu)
cs.colors[6] = colorant"green" # for testing :)
This one (RdBu
) is from ColorBrewer, so perhaps you can locate the method they used to build this scheme and modify it...
To build color schemes in a more programmatic way, you could look at ColorSchemeTools.jl but I don't know the method for making this particular one.
Oh I did not mean to go as deep as adapting the code that generated the original colors! I was merely fishing for things like you just wrote, which looks much simpler than mine. For the record, I think I will be using a function like below from now on
function withwhitecenter(cs)
cs = deepcopy(cs)
cs.colors[end÷2+1] = colorant"white"
return cs
end