Transparent surfaces in Makie.jl

I just got to know Makie.jl and I am enjoying its consistency. I am trying to plot points on the sphere, where the sphere should be a little transparent, since the points on the opposite side should be a little visible. My approach
MWE reads as

using Makie
using Colors
using GeometryTypes
n = 33
u = range(0,stop=2*π,length=n);
v = range(0,stop=π,length=n);

x = zeros(n,n); y = zeros(n,n); z = zeros(n,n)
for i in 1:n
    for j in 1:n
        x[i,j] = cos.(u[i]) * sin(v[j]);
        y[i,j] = sin.(u[i]) * sin(v[j]);
        z[i,j] = cos(v[j]);
    end
end

scene = surface(  x,y,z, show_axis=false, alpha=0.8,
  color = fill(RGBA(1.,1.,1.,0.8),n,n),
  limits=HyperRectangle(Vec(-1.01,-1.01,-1.01),Vec(1.01,1.01,1.01))  )
wireframe!(  scene,x,y,z, show_axis=false,
  linewidth=1.2,color=RGBA(0.0,0.0,0.2,0.8)  )
scatter!(  scene,
  Point3f0.([ [1.,0.,0.], 1/sqrt(2)*[1.,1.,0], 1/sqrt(3)*[1.,1.,1.], [-1.,0.,0.], [0.,0.,1.] ]),
  color=:blue, markersize=0.05, show_axis=false  )

and produces.


I tried both alpha= and an RGBA for the surface, but somehow the white sphere is not transparent. How can I get the surface transparent?

Further in Jupyter this code produces both an (rendered) image (basically the one above), and a window that is interactive (Julia-Window). Is there an embedded interactive way for Jupyter? And can I deactivate one of the two outputs?

1 Like

This is currently an oddity from a trade off for transparency rendering…
You need to put transparency at least to 0.4 to actually take effect :frowning:

using Makie
using Colors
using GeometryTypes
n = 33
u = range(0,stop=2*π,length=n);
v = range(0,stop=π,length=n);
x = zeros(n,n); y = zeros(n,n); z = zeros(n,n)
for i in 1:n
    for j in 1:n
        x[i,j] = cos.(u[i]) * sin(v[j]);
        y[i,j] = sin.(u[i]) * sin(v[j]);
        z[i,j] = cos(v[j]);
    end
end

scene = surface(
  x,y,z,
  show_axis = false,
  color = fill(RGBA(1.,1.,1.,0.4), n, n),
  limits = HyperRectangle(Vec3f0(-1.01), Vec3f0(1.01))
)
wireframe!(
  scene, x, y, z,
  show_axis = false,
  linewidth = 1.2, color = RGBA(0.0,0.0,0.2,0.4))
scatter!(
  scene,
  Point3f0[
    (1.,0.,0.), 1/sqrt(2) .* (1.,1.,0), 1/sqrt(3) .* (1.,1.,1.), (-1.,0.,0.), (0.,0.,1.)
  ],
  color = :blue, markersize = 0.05, show_axis = false
)
2 Likes

I put that on the final release todo list :slight_smile:

1 Like

Thanks, that was not mentioned anywhere, so I tried a few “old” approaches like the alpha. I like the RGBA more, though,
And thanks for such a nice approach, having tried a few others, Makie seems the oe fitting my needs best for now.

…and if an interactive HTML-one for Jupyter would be available/possbile, that would be just perfect :slight_smile: