# Color opacity

**URL:** <https://discourse.julialang.org/t/color-opacity/84063>\
**Category:** New to Julia\
**Tags:** colors, plots\
**Created:** [July 11, 2022, 5:05pm UTC](https://discourse.julialang.org/t/color-opacity/84063 "2022-07-11T17:05:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmed](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ahmed](https://discourse.julialang.org/u/ahmed)\
**Post date:** [July 11, 2022, 5:05pm UTC](https://discourse.julialang.org/t/color-opacity/84063/1 "2022-07-11T17:05:44Z")

</div>

I have a variable that I would like to assign the color red to it simply by using  
RGB{Float64}(1, 0, 0) but I’d like the absolute value of the variable to determine the opacity of the color. How can one change the color opacity in Julia?

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [July 11, 2022, 5:10pm UTC](https://discourse.julialang.org/t/color-opacity/84063/2 "2022-07-11T17:10:41Z")

</div>

Opacity is represented by the `A` component of an `RGBA` value. For an opaque red, you’d use `RGBA{Float64}(1, 0, 0, 1)`.

---

<div class="post-metadata">

**Author:** ![ahmed](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ahmed](https://discourse.julialang.org/u/ahmed)\
**Post date:** [July 11, 2022, 5:35pm UTC](https://discourse.julialang.org/t/color-opacity/84063/3 "2022-07-11T17:35:26Z")

</div>

Thanks for your reply. I don’t seem to get a transparent color when the A component is zero though. like I tried this simple test `scatter([1,2],[1,2],color=[RGBA{Float64}(1,0,0,1),RGBA{Float64}(1,0,0,0)],legends=false)` where the point (2,2) should be transparent but it comes out same as (1,1).

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [July 11, 2022, 5:43pm UTC](https://discourse.julialang.org/t/color-opacity/84063/4 "2022-07-11T17:43:04Z")

</div>

Looks like transparency might be buggy for the GR.jl backend. Try switching to the PyPlot backend:

```julia
julia> Pkg.add("PyPlot"); pyplot()

```

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [July 11, 2022, 5:48pm UTC](https://discourse.julialang.org/t/color-opacity/84063/5 "2022-07-11T17:48:52Z")

</div>

With GR, use `markeralpha` to set alphas separately from the color

```julia
scatter([1,2],[1,2],markercolor=[RGB{Float64}(1,0,0),RGB{Float64}(1,1,0)],markeralpha=[1,0],legends=false)

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [July 11, 2022, 6:50pm UTC](https://discourse.julialang.org/t/color-opacity/84063/6 "2022-07-11T18:50:55Z")

</div>

You can do this more conveniently as:

```julia
using Plots; gr()
fc = [RGBA(1,0,0,1.0), RGBA(1,0,0,0.1)]
scatter([1,2], [1,2], c=fc, alpha=fc, legend=false)

```

 ![Plots_scatter_transparency](https://global.discourse-cdn.com/julialang/original/3X/f/2/f2f8f15d2778a3977c529cc55f835262e8f3a16c.png)
