Hi all, I’m looking to make a plot of some rasters (or if all else fails heatmaps) of values using Makie where the base color is independent of the opacity. Trying to blend two bits of information here where there are two different arrays, one for the colorrange, and one for alpha values.
From looking at the gallery and docs, they all mostly show alpha being fed in as a single parameter. Is there a way to achieve the above?
Thanks all for the suggestion. I had thought of viz but I think it only supports Polygonal data? The rasters would be matrix information.
As for the recipe by @aplavin, that certainly looks like an option. But I was having some trouble getting it to run as it seems Makie.MakieCore.color_and_colormap!() is not a function found in the library anymore. Has there been a change to the package perhaps?
The links were helpful in pointing to the Colorfy.jl package though. It’s a very in elegant solution, but I’ve tried using a scatter plot with :rect markers and precomputed colors with Colorfy.jl to produce a plot. But if any of you have more insights on the above, would be keen to hear!
Here’s a manual solution, it’s not too difficult but yeah maybe Makie could have more convenience for it. I guess the reason it doesn’t is because a varying colormap plus varying alpha is difficult to interpret.
mat = reshape(1:16, 4, 4)
alphas = reshape(repeat(range(0, 1, length = 8), 2), 4, 4)
mi, ma = extrema(mat)
cg = cgrad(:viridis)
# index into colormap with values scaled to [0, 1]
colors = getindex.(Ref(cg), (mat .- mi) ./ (ma - mi))
colors_alpha = Makie.to_color(tuple.(colors, alphas))
image(colors_alpha)
Yes, Makie had a large breaking change recently. I don’t know where this specific function went, but you might try Makie.color_and_colormap! (ie, remove MakieCore).