# How to get a Semi transparent sphere in Makie?

**URL:** <https://discourse.julialang.org/t/how-to-get-a-semi-transparent-sphere-in-makie/117944>\
**Category:** Visualization\
**Created:** [August 8, 2024, 7:50am UTC](https://discourse.julialang.org/t/how-to-get-a-semi-transparent-sphere-in-makie/117944 "2024-08-08T07:50:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [August 8, 2024, 7:50am UTC](https://discourse.julialang.org/t/how-to-get-a-semi-transparent-sphere-in-makie/117944/1 "2024-08-08T07:50:16Z")

</div>

A few years back I asked a question, that I could not fully resolve. At JuliaCon I think I heard it is now possible, so I’ll give it a new try. If I do something like (e.g. in a Pluto cell)

```julia
begin
using WGLMakie, Colors, Manifolds #versions 0.10.5, 0.12.11, 0.9.20
# A sphere
n = 45
u = range(0,stop=2*π,length=n);
v = range(0,stop=π,length=n);
sx = zeros(n,n); sy = zeros(n,n); sz = zeros(n,n)
for i in 1:n
    for j in 1:n
        sx[i,j] = cos.(u[i]) * sin(v[j]);
        sy[i,j] = sin.(u[i]) * sin(v[j]);
        sz[i,j] = cos(v[j]);
    end
end
fig, ax, plt = surface(
  sx,sy,sz,
  color = fill(RGBA(1.,1.,1.,0.3), n, n),
  shading = Makie.automatic
)
ax.show_axis = false
wireframe!(ax, sx, sy, sz, color = RGBA(0.5,0.5,0.7,0.3))
# Scatter some points
    π1(x) = x[1]
    π2(x) = x[2]
    π3(x) = x[3]
	M = Manifolds.Sphere(2)
	pts = [rand(M) for _ in 1:300]
	scatter!(ax, π1.(pts), π2.(pts), π3.(pts); markersize=4, color=:blue)
	fig
end

```

I get an image like

 ![Screenshot 2024-08-08 at 09.44.45](https://global.discourse-cdn.com/julialang/original/3X/0/2/02a80394507b5b7d19bce98a28567c5847cdab97.jpeg)

What I would love to have is actual transparency, From the 300 points some are also on the back of the sphere – and just seeing them shining through would be great. If they were for example a curve, one could easily see which part is upfront, which behind.

Is that doable in Makie? I already do use transparency in the color, that does not seem to do the job here.

---

<div class="post-metadata">

**Author:** ![p\_f](https://avatars.discourse-cdn.com/v4/letter/p/45deac/32.png) [@p\_f](https://discourse.julialang.org/u/p_f)\
**Post date:** [August 8, 2024, 9:33am UTC](https://discourse.julialang.org/t/how-to-get-a-semi-transparent-sphere-in-makie/117944/2 "2024-08-08T09:33:14Z")

</div>

You can pass `alpha = x` and `transparency = true` when you call `surface`:

```julia
fig, ax, plt = surface(sx,sy,sz,color = fill(:red, n, n),invert_normals=true,alpha=0.5,transparency=true)
meshscatter!(ax, sx[1:10:end], sy[1:10:end], sz[1:10:end], color = :blue)
fig

```

or just add `transparency=true` if you pass the alpha value to the colour:

```julia
fig, ax, plt = surface(
  sx,sy,sz,
  color = fill((:red,0.5), n, n),invert_normals=true,transparency=true)
meshscatter!(ax, sx[1:10:end], sy[1:10:end], sz[1:10:end], color = :blue)
fig

```

![image](https://global.discourse-cdn.com/julialang/original/3X/5/6/56516ad75a6779741727e1999d97487545c1e4d5.png)

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [August 8, 2024, 5:37pm UTC](https://discourse.julialang.org/t/how-to-get-a-semi-transparent-sphere-in-makie/117944/3 "2024-08-08T17:37:47Z")

</div>

Thanks, that did indeed work as soon as I applied it to both the mesh and the surface.
