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)
I’d like to do essentially the same thing. I’d like to set the color using the color map (based on a variable that varies between 0 and 1, but I’d like to vary the opacity so that early points are transparent and late points are opaque.
[imagine the first makie example here:
but the “trail” of the trajectory slowly fades. Note that this example seems to fade, but that is just an artifact of the colormap. If you use a different colormap (that doesn’t end in black), it won’t appear that way.]
Thanks for the pointer. I still can’t figure out how to modify the Lorenz example to use a color map AND opacity at the same time. I don’t know how to modify the Observable for colors.