I want to plot points/lines with colors and changing transparencies. The Makie doc shows some usages, but what I need is to input a numerical value for color and another numerical value for the transparency.
This simple example works
using GLMakie
c = to_color(:purple)
npoints = 10
color = [RGBAf(c.r, c.g, c.b, (i/npoints)^2) for i in 1:npoints]
lines(1:10, 1:10; color)
so does this
lines(1:10, 1:10; color=1:10, colorrange=(1,10))
But what if I want something like
lines(1:10, 1:10; color=(1:10, 0.5), colorrange=(1,10)) # not working so far
i.e., changing color with a fixed transparency alpha? Or one step further, with a changing transparency setup?
For the first, do colormap = (colormap, alpha). For the second, you could construct the colormap with changing transparency. Like Colors.alphacolor.(Makie.to_colormap(x), alphavalues)
It is still different from what I need. In this way for example, red always corresponds to high alpha, while purple always corresponds to low alpha. I want the transparency to be independent of RGB (i.e. the numerical value x). Logically adding alpha to the colormaps won’t work; probably what I need is a way to convert a numerical value x to RGB while keeping alpha a separate variable,
c = to_color(:purple)
npoints = 10
# Here RGB are fixed, but alpha is a variable; how to map a value x to the RGB in the target colormap?
color = [RGBAf(c.r, c.g, c.b, (i/npoints)^2) for i in 1:npoints]
julia> Makie.to_colormap(1.0)
ERROR: MethodError: no method matching to_colormap(::Float64)
julia> Makie.to_colormap([1.0, 2.0])
ERROR: MethodError: no method matching alpha(::Float32)