# Makie color transparency

**URL:** <https://discourse.julialang.org/t/makie-color-transparency/98015>\
**Category:** Visualization\
**Tags:** plotting, makie\
**Created:** [April 27, 2023, 8:54pm UTC](https://discourse.julialang.org/t/makie-color-transparency/98015 "2023-04-27T20:54:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![henry2004y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henry2004y/32/9284_2.png) [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Post date:** [April 27, 2023, 8:54pm UTC](https://discourse.julialang.org/t/makie-color-transparency/98015/1 "2023-04-27T20:54:09Z")

</div>

Hi,

I want to plot points/lines with colors and changing transparencies. The [Makie doc](https://docs.makie.org/stable/documentation/colors/index.html#cheat_sheet) 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

```julia
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

```julia
lines(1:10, 1:10; color=1:10, colorrange=(1,10))

```

But what if I want something like

```julia
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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 28, 2023, 1:24am UTC](https://discourse.julialang.org/t/makie-color-transparency/98015/2 "2023-04-28T01:24:41Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![henry2004y](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henry2004y/32/9284_2.png) [@henry2004y](https://discourse.julialang.org/u/henry2004y)\
**Post date:** [April 28, 2023, 8:30am UTC](https://discourse.julialang.org/t/makie-color-transparency/98015/3 "2023-04-28T08:30:53Z")

</div>

Thank you! The first one works nicely, e.g.:

```julia
lines(1:10, 1:10; color=1:10, colorrange=(1,10), colormap=(:turbo, 0.5))

```

For the second one, although the following works:

```julia
using GLMakie.Colors
cmap = Colors.alphacolor.(resample_cmap(:turbo, 10), 0.1:0.1:1.0)
lines(1:10, 1:10; color=1:10, colorrange=(1,10), colormap=cmap)

```

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,

```julia
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
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)

```

How should I do that?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [April 28, 2023, 10:38am UTC](https://discourse.julialang.org/t/makie-color-transparency/98015/4 "2023-04-28T10:38:16Z")

</div>

We don’t have separate alpha (for other reasons) so you’d have to do the colormap lookup manually and then assign alpha values to those looked up colors. There is no clear public API for this though and we’re in the midst of refactoring colormaps and color conversions ourselves currently [Clean up colormap handling and implement colorscale by SimonDanisch · Pull Request #2900 · MakieOrg/Makie.jl · GitHub](https://github.com/MakieOrg/Makie.jl/pull/2900)

---

<div class="post-metadata">

**Author:** ![Gus\_Hart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gus_hart/32/6987_2.png) [@Gus\_Hart](https://discourse.julialang.org/u/Gus_Hart)\
**Post date:** [June 24, 2023, 3:57am UTC](https://discourse.julialang.org/t/makie-color-transparency/98015/5 "2023-06-24T03:57:02Z")

</div>

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:

> **[Home · Makie](https://docs.makie.org/stable/#example)**
>
> Create impressive data visualizations with Makie, the plotting ecosystem for the Julia language. Build aesthetic plots with beautiful customizable themes, control every last detail of publication quality vector graphics, assemble complex layouts and...

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.]

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [June 24, 2023, 7:00am UTC](https://discourse.julialang.org/t/makie-color-transparency/98015/6 "2023-06-24T07:00:08Z")

</div>

[Tyler.jl/docs/examples/UserGuide/whale\_ex.jl at 9d32abe9f25a77d774f6b5d49f2f24667ef0e496 · MakieOrg/Tyler.jl · GitHub](https://github.com/MakieOrg/Tyler.jl/blob/9d32abe9f25a77d774f6b5d49f2f24667ef0e496/docs/examples/UserGuide/whale_ex.jl#L44) check here.

---

<div class="post-metadata">

**Author:** ![Gus\_Hart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gus_hart/32/6987_2.png) [@Gus\_Hart](https://discourse.julialang.org/u/Gus_Hart)\
**Post date:** [June 25, 2023, 1:06am UTC](https://discourse.julialang.org/t/makie-color-transparency/98015/7 "2023-06-25T01:06:45Z")

</div>

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.
