Progressive colormap transparency

I was wondering: what is the best way to make a colormap progressively transparent?
In practice I’d like to use a colormap (e.g. :bilbao) but I’d like the color to progressively become transparent for low values of the range.
Any hint is welcome!

ps: I’m currently using CairoMakie.

one possibility is Making colorschemes · ColorSchemeTools

1 Like

You can construct a vector of (color,alpha) pairs for all data points, but the best way to do that is unclear to me. e.g.

x = 1:100
y = sin.(2*pi .* x ./ 100)

cmap = cgrad(:viridis,length(x),categorical=true)
colors = [(cmap[i],1-i/length(x)) for i in 1:length(x)]
f,ax,s=lines(x,y,color=colors,linewidth=10)

but the cgrad function seems a bit strange to me, not returning a length of 100 for some colormaps without categorical=true?

there’s also get(Makie.ColorSchemes.viridis,range(0,1,100)) instead of cgrad, but that doesn’t accept symbols for colormaps so seems a bit annoying to use

1 Like