# Makie isosurface transparency?

**URL:** <https://discourse.julialang.org/t/makie-isosurface-transparency/65214>\
**Category:** General Usage\
**Tags:** makie\
**Created:** [July 23, 2021, 11:36pm UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214 "2021-07-23T23:36:08Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [July 23, 2021, 11:36pm UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/1 "2021-07-23T23:36:08Z")

</div>

In Makie is there a way to make an isosurface have some partial transparency? There used to be I think, but I cant see an alpha option or similar

[http://makie.juliaplots.org/dev/plotting\_functions/volume.html](http://makie.juliaplots.org/dev/plotting_functions/volume.html)

Over at [https://lazarusa.github.io/BeautifulMakie/surfWireLines/KleinBottle/](https://lazarusa.github.io/BeautifulMakie/surfWireLines/KleinBottle/)

I notice that a partially transparent colormap can be passed to mesh:

`colormap = (:Spectral_11,0.95)`

but if I try it with `volume` the transparency doesn’t work.

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [July 24, 2021, 9:51pm UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/2 "2021-07-24T21:51:40Z")

</div>

if I use `transparency=true`, i.e.

```julia
r = LinRange(-1, 1, 100)
cube = [(x.^2 + y.^2 + z.^2) for x = r, y = r, z = r]
cube_with_holes = cube .* (cube .> 1.4)
volume(cube_with_holes, algorithm = :iso, isorange = 0.05, isovalue = 1.7,transparency=true)

```

I get the following. But this is not really transparent in the sense that matters for me. The back surface is not visible through the front surface.

 ![Screen Shot 2021-07-25 at 9.50.16 AM](https://global.discourse-cdn.com/julialang/original/3X/3/b/3bbb8852c2b56863e8bf33df49db3bd96d0d68a3.png)

---

<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 25, 2021, 12:05am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/3 "2021-07-25T00:05:16Z")

</div>

Check the absorption and contour suggestions in this [amazing post](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/9).

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [July 25, 2021, 6:10am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/4 "2021-07-25T06:10:36Z")

</div>

Ok, some progress. If I do, e.g.

```julia
contour(cube_with_holes,levels=[1.65,1.7],colormap=:blues,alpha=.3,colorrange=[-8,8])

```

I get the result

 ![Screen Shot 2021-07-25 at 6.09.23 PM](https://global.discourse-cdn.com/julialang/original/3X/a/c/acf25b2356e0d42565536898d600cffc6904b534.jpeg)

Not quite what I want though. Quite dark, hard to get a clear surface

---

<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:** [July 25, 2021, 6:55am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/5 "2021-07-25T06:55:50Z")

</div>

This would be really good to add to the docs, I never need volume plots but there is just one example and it’s not clear at all how to use the other modes.

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [July 25, 2021, 7:51am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/6 "2021-07-25T07:51:30Z")

</div>

I figured finding an example of roughly what I am trying to do would be more useful. I am aiming for something like the fourth example here:

[https://plotly.com/python/3d-isosurface-plots/](https://plotly.com/python/3d-isosurface-plots/)

---

<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:** [July 25, 2021, 10:19am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/7 "2021-07-25T10:19:00Z")

</div>

I use [this trick](https://discourse.julialang.org/t/makie-volume-animation-froze/43707/21) often(https://), it gives nice results.

```julia
colors = to_colormap(:balance)
n = length(colors)
alpha = [ones(n÷3);zeros(n-2*(n÷3));ones(n÷3)]
cmap_alpha = RGBAf0.(colors, alpha)

```

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [August 19, 2021, 9:46am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/8 "2021-08-19T09:46:19Z")

</div>

I think this shows the issue clearly.

I would expect to see two intersecting ellipsoids, with axis sitting behind (less visible due to being behind more than one layer). Here I plotted the smaller (closer) surface first. The impression is that both sit behind the axis, and the closer one appears behind the further because transparency is only with respect to axes. I have tried applying an alpha to colormap (suggested above), but I haven’t had much luck improving this

```julia
	using GLMakie
	X = -40:5:40
	ellipse1 = [X^2/2 + Y^2 + 2Z^2 for X in X, Y in X, Z in X];
	ellipse2 = [X^2/2 + (Y-20)^2 + 2Z^2 for X in X, Y in X, Z in X];
	v1=volume(ellipse2, algorithm = :iso,isovalue =350,isorange = 50,transparency=true)
	volume!(ellipse1, algorithm = :iso, isovalue =700,isorange = 50,transparency=true)
	v1

```

 ![Screen Shot 2021-08-19 at 9.38.59 PM](https://global.discourse-cdn.com/julialang/original/3X/1/d/1dacd57c43d0eccdd8b1eff4a2a33dc0bba485b6.png)

---

<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:** [August 19, 2021, 11:10pm UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/9 "2021-08-19T23:10:22Z")

</div>

> [@AshtonSBradley](#):
>
> ```julia
> X = -40:5:40
> ellipse1 = [X^2/2 + Y^2 + 2Z^2 for X in X, Y in X, Z in X];
> ellipse2 = [X^2/2 + (Y-20)^2 + 2Z^2 for X in X, Y in X, Z in X];
> v1=volume(ellipse2, algorithm = :iso,isovalue =350,isorange = 50,transparency=true)
> volume!(ellipse1, algorithm = :iso, isovalue =700,isorange = 50,transparency=true)
> 
> ```

did you tried like this:

```julia
using GLMakie, ColorSchemes
cbarPal= :plasma
cmap = get(colorschemes[cbarPal], LinRange(0,1,100))
cmap2 = [(cmap[i],0.65) for i in 1:100]

X = -40:5:40
ellipse1 = [X^2/2 + Y^2 + 2Z^2 for X in X, Y in X, Z in X];
ellipse2 = [X^2/2 + (Y-20)^2 + 2Z^2 for X in X, Y in X, Z in X];
volume(ellipse2, algorithm = :iso,isovalue =350,isorange = 50, colormap=cmap2)
volume!(ellipse1, algorithm = :iso, isovalue =700,isorange = 50, colormap=cmap2)
current_figure()

```

 ![Screenshot 2021-08-20 at 01.16.43](https://global.discourse-cdn.com/julialang/original/3X/7/8/7806becfef6c73cbdcc93fcf148899dc5b55db68.png)

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [August 19, 2021, 11:53pm UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/10 "2021-08-19T23:53:03Z")

</div>

Ok that looks great, thanks!

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [August 20, 2021, 2:38am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/12 "2021-08-20T02:38:30Z")

</div>

> [@lazarusA](#):
>
> did you tried like this:
> 
> ```julia
> using GLMakie, ColorSchemes
> cbarPal= :plasma
> cmap = get(colorschemes[cbarPal], LinRange(0,1,100))
> cmap2 = [(cmap[i],0.65) for i in 1:100]
> 
> X = -40:5:40
> ellipse1 = [X^2/2 + Y^2 + 2Z^2 for X in X, Y in X, Z in X];
> ellipse2 = [X^2/2 + (Y-20)^2 + 2Z^2 for X in X, Y in X, Z in X];
> volume(ellipse2, algorithm = :iso,isovalue =350,isorange = 50, colormap=cmap2)
> volume!(ellipse1, algorithm = :iso, isovalue =700,isorange = 50, colormap=cmap2)
> current_figure()
> 
> ```

Ok, getting closer. Still puzzling: I make a torus geometry. Why isn’t the full torus visible even though there is an alpha? It seems that the alpha is applied to another surface (dual ellipsoid case above), but not to different parts of the same surface. We should be able to see the core of the torus, and the back surface:

```julia
using GLMakie
using ColorSchemes
cmap3 = get(colorschemes[:plasma], LinRange(0,1,100))
	cmap4 = [(cmap3[i],0.65) for i in 1:100]
	ξ = -40:1:40
	c = 20
	a = 15
	torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]
	volume(torus, algorithm = :iso,isovalue =100,isorange =50, colormap=cmap4)
	current_figure()

```

 ![Screen Shot 2021-08-20 at 2.35.43 PM](https://global.discourse-cdn.com/julialang/original/3X/c/a/cacab84b5583f75b98b8ad1291816948d6e61298.jpeg)

I would expect something more like this:

![Screen Shot 2021-08-20 at 2.02.55 PM](https://global.discourse-cdn.com/julialang/original/3X/a/a/aa65dca84d83a2202c8a0a9f2dc6ef0bbdb24e56.png)

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [June 16, 2024, 11:45pm UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/13 "2024-06-16T23:45:23Z")

</div>

It seems like `contour` can sort of do this, but the visibility is not great and there is also a loss of surface information and the result is not really very clear:

```julia
(@v1.10) pkg> status GLMakie
Status `~/.julia/environments/v1.10/Project.toml`
  [e9467ef8] GLMakie v0.10.2

using GLMakie
using ColorSchemes
cmap3 = get(colorschemes[:plasma], LinRange(0,1,100))
	cmap4 = [(cmap3[i],0.65) for i in 1:100]
	ξ = -40:1:40
	c = 20
	a = 15
	torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]
contour(torus,levels=[1],colormap=:greens,alpha=0.1)

```

Maybe I am not using the right parameters or light sources?  
Is there a way to get the best of both worlds, more like the matlab figure above?

I have also tried making the colormap transparent, and that didn’t help.

 ![Screenshot 2024-06-17 at 11.42.48 AM](https://global.discourse-cdn.com/julialang/original/3X/2/c/2cf3cc4ad86b17fab146cb2a71a08c09b9138472.png)

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [June 19, 2024, 10:31am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/14 "2024-06-19T10:31:55Z")

</div>

After a bit of playing around with parameters, I reached this result for a transparent isosurface using a mesh:

 ![Screenshot 2024-06-19 at 10.11.25 PM](https://global.discourse-cdn.com/julialang/original/3X/3/c/3cc4f6358cdea85019a05c662bbbd45d6891133a.png)

The code looks like this

```julia
using GLMakie, Meshing, GeometryBasics

ξ = -40:.5:40
c = 20
a = 15
torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]

##
with_theme(theme_dark()) do
algo = MarchingCubes(iso=100)

vts, fcs = isosurface(torus, algo)
mc = Makie.GeometryBasics.Mesh(vts .|> Makie.Point3, fcs .|> Makie.GeometryBasics.TriangleFace)

f ,ax,pl=mesh(normal_mesh(mc), 
    color=(:dodgerblue, .7), 
    diffuse = Vec3f0(0.8),
    specular = Vec3f0(1.1),
    shininess = 30f0,
    backlight = 5f0,
    axis = (show_axis = false, ))
    f
end

```

---

<div class="post-metadata">

**Author:** ![AshtonSBradley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ashtonsbradley/32/11140_2.png) [@AshtonSBradley](https://discourse.julialang.org/u/AshtonSBradley)\
**Post date:** [August 18, 2024, 4:51am UTC](https://discourse.julialang.org/t/makie-isosurface-transparency/65214/15 "2024-08-18T04:51:42Z")

</div>

I have updated this to work with the for recent changes to GeometryBasics and Meshing.
