How to create circular color gradient plot?

I see a lot of examples how to do it in Python, but no example how to do it in Julia Makie.

What should I use, mash?

We currently don’t have a circular gradient, but I think it has been requested before…
What do you want to achieve? Right now you will need to use a Mesh, to emulate it, e.g. like this:

using GLMakie, LinearAlgebra

cmap = to_colormap(:viridis)
function color(i, j)
    distance_01 = norm(Point2f(i, j)) / sqrt(2)
    return Makie.interpolated_getindex(cmap, distance_01, (0, 1))
end

colors = [color(i, j) for i in -1:0.1:1, j in -1:0.1:1]

mesh(Rect2f(0, 0, 1, 1); color=colors, shading=false)

1 Like

Hello!
Thank you very much for your answer!
I would like to recreate this picture: at least e and h.

offtop, but also important
Is there a Kindlmann colormap in Julia?
https://www.kennethmoreland.com/color-advice/

don’t think so, might be a good PR to colorschemes?

1 Like

I succeeded to reproduce the first circular color gradient, and plot it with PlotlyJS:

using PlotlyJS
mycolors =  ["#ff0000", "#ffff00", "#00ff00", "#00ffff", "#0000ff", "#ff00ff",  "#ff0000"]
cmap =[[k/6, c] for (k, c) in zip(0:6, mycolors)];
xl=yl= range(-1, 1, 100)
x = ones(length(yl)) * xl'; y= yl* ones(length(xl))';
z =@. √(x^2 +y^2)
plt=Plot(heatmap(z=z, colorscale=cmap, showscale=false),
         Layout(width=350, height=350, xaxis_visible=false, yaxis_visible=false))

circular-cmap
Changing the hexcolors in mycolors you can get another colo gradient. But by the nowadays standards for colorschemes, this is a bad gradient, because it exhibits bands.
Replacing colorscale=cmap, by colorscale=reverse(colors.turbo) (i.e. using google turbo colormap, as an improved version of jet/rainbow colormap) we get a better circular color gradient:
circular-turbo
or colorscale=reverse(colors.curl) (curl is a cmocean diverging colorscheme):
circular-rev-curl

LE: to get the plot (h) define the kinglman colormao as follows:

kmancolors= ["rgb(255, 255, 255)",
             "rgb(252, 220, 200)",
             "rgb(205, 205, 10)",
             "rgb(97, 193, 9)",
             "rgb(15, 168, 8)",
             "rgb(7, 137, 66)",
             "rgb(5, 105, 105)",
             "rgb(7, 69, 142)",
             "rgb(24, 8, 163)",
             "rgb(39, 4, 82)",
             "rgb(0,0,0)"]
kman_cmap=[[k/(length(kmancolors)-1), c] for (k,c) in zip(0:(length(kmancolors)-1), kmancolors)]

and set colorscale=kman_cmap:
kinglmancmap

2 Likes

With GMT.jl this should be a one liner but I’m not at a computer to confirm. See background images example in Subplots

1 Like