# Transparent plotting in Makie

**URL:** <https://discourse.julialang.org/t/transparent-plotting-in-makie/67625>\
**Category:** Visualization\
**Tags:** plotting, makie\
**Created:** [September 3, 2021, 5:57am UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625 "2021-09-03T05:57:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![yosuga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yosuga/32/52638_2.png) [@yosuga](https://discourse.julialang.org/u/yosuga)\
**Post date:** [September 3, 2021, 5:57am UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/1 "2021-09-03T05:57:30Z")

</div>

[BeautifulMakie](https://lazarusa.github.io/BeautifulMakie/) is very helpful for 3D plotting.  
But, in this [volume with scatters, x,y,z, f(x,y,z)](https://lazarusa.github.io/BeautifulMakie/surfWireLines/volumeScatters/#volume_with_scatters_xyz_fxyz) example, I can’t see inside the box e.g. the values at (x,y,z)=(5,5,5) or (0,0,0). I want something like [this example,“DensityPlot3D[x y z, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]”](https://reference.wolfram.com/language/ref/DensityPlot3D.html.en?source=footer). In other words, I want to color only the points that are within a certain value of f(x,y,z), and make the other points (almost) transparent.  
How do you do that?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 3, 2021, 9:16am UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/2 "2021-09-03T09:16:41Z")

</div>

You should take a look at `contour(vol)` instead of using a scatter 😉  
Also: [volume](http://makie.juliaplots.org/v0.15.2/examples/plotting_functions/volume/index.html)

---

<div class="post-metadata">

**Author:** ![yosuga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yosuga/32/52638_2.png) [@yosuga](https://discourse.julialang.org/u/yosuga)\
**Post date:** [September 3, 2021, 10:17am UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/3 "2021-09-03T10:17:05Z")

</div>

Thanks. I forgot to say that I’m treating a function defined on a discrete space, e.g. an electron density on a lattice. For this reason, I need a scatter plotting not a volume plotting. Is it possible with a scatter?

---

<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:** [September 3, 2021, 4:04pm UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/4 "2021-09-03T16:04:30Z")

</div>

I see, so probably you are looking for something like this (left panel):

 ![Screenshot 2021-09-03 at 18.01.44](https://global.discourse-cdn.com/julialang/original/3X/a/2/a289f8bf9039e3cc5d0744dd458510dd95d4fd02.jpeg)

Probably, you could go and see the code at [GLMakie.jl - Julia Data Science](https://juliadatascience.io/glmakie) (at the bottom), or wait a little bit, while I upload a simpler version to the Gallery.

---

<div class="post-metadata">

**Author:** ![yosuga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yosuga/32/52638_2.png) [@yosuga](https://discourse.julialang.org/u/yosuga)\
**Post date:** [September 3, 2021, 4:58pm UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/5 "2021-09-03T16:58:04Z")

</div>

Thanks for comment! It is good that there are regions with no rectangles, but Not exactly. This is a plot of z=f(x,y) in (x,y,z) space. Besides the plane with z=0 (yellow plane) is not needed.  
For example, Fig.6 (a) in [this paper](https://arxiv.org/abs/2008.07237) is what I want.  
Normally, transparent areas would be painted black, but by adjusting the areas to be colored, they made them transparent.

---

<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:** [September 3, 2021, 5:02pm UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/6 "2021-09-03T17:02:32Z")

</div>

Yes, indeed is possible to do that figure. I will upload an example later.

---

<div class="post-metadata">

**Author:** ![yosuga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yosuga/32/52638_2.png) [@yosuga](https://discourse.julialang.org/u/yosuga)\
**Post date:** [September 3, 2021, 6:03pm UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/7 "2021-09-03T18:03:52Z")

</div>

In the last decade or so, topological phases of non-Hermitian systems have been well studied, because non-Hermitian systems have richer mathematical/physical properties beyond Hermitian one.  
One practical example is [a topological laser](https://www.science.org/doi/10.1126/science.aar4005).  
Lasers are essentially non-hermitian systems due to a laser oscillation, and a non-trivial topology provides “topologically protected” (robustness in some sense) lasing modes.

I had already read your comment, but I am a slow writer, so it took me a while to reply.  
Anyway, I’m looking forward to it!

---

<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:** [September 3, 2021, 6:22pm UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/8 "2021-09-03T18:22:26Z")

</div>

Yes, indeed. At some point I was doing some research with non-Hermitian systems, but I didn’t see too much the point of doing that, so I’m not longer up to date in the field. 😃 , anyhow… here is the plot, I hope it helps.

 ![volumeTransparent](https://global.discourse-cdn.com/julialang/original/3X/5/f/5f9ede847871625c8f9824d1ca6f01da0d64dd72.jpeg)

For completeness I also plotted other ways to plot the same data. See the full code as usual at [https://lazarusa.github.io/BeautifulMakie/surfWireLines/volumeTransparent/](https://lazarusa.github.io/BeautifulMakie/surfWireLines/volumeTransparent/)

---

<div class="post-metadata">

**Author:** ![yosuga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yosuga/32/52638_2.png) [@yosuga](https://discourse.julialang.org/u/yosuga)\
**Post date:** [September 3, 2021, 6:49pm UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/9 "2021-09-03T18:49:31Z")

</div>

Oh, I see. 😊  
Thank you. I really appreciate it. I 'll try it tomorrow.

---

<div class="post-metadata">

**Author:** ![yosuga](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yosuga/32/52638_2.png) [@yosuga](https://discourse.julialang.org/u/yosuga)\
**Post date:** [September 4, 2021, 9:42am UTC](https://discourse.julialang.org/t/transparent-plotting-in-makie/67625/10 "2021-09-04T09:42:12Z")

</div>

```julia
@time let
    
    L = 15
    x = -L:L
    y = -L:L
    z = -L:L
    positions = vec([(ix, iy, iz) for ix in x, iy in y, iz in z])
    
    ρ(ix,iy,iz) = (ix^2 + iy^2 + iz^2)/3L^2
    abs2ψ = Float64[ρ(ix,iy,iz) for ix in x, iy in y, iz in z]
    
    cmap = :Blues_9
    colors = to_colormap(cmap,L^3) #step size of cmap
    n = length(colors)
    g(x) = x^8 #transparency weight
    alphas = [g(x) for x in LinRange(0,1,n)]
    cmap_alpha = RGBAf0.(colors, alphas)   
    
    fig = Figure(resolution = (1200,1200))
    ax1 = Axis3(fig[1,1], perspectiveness = 0.5, azimuth = 7.3, elevation = 0.57,  
            xlabel = "x label", ylabel = "y label", zlabel = "z label",
            aspect = (1,1,1))
    ax2 = Axis3(fig[2,1], perspectiveness = 0.5, azimuth = 7.3, elevation = 0.57,  
            xlabel = "x label", ylabel = "y label", zlabel = "z label",
            aspect = (1,1,1))
    
    meshscatter!(ax1,positions, color = vec(abs2ψ), colorrange = (minimum(abs2ψ),maximum(abs2ψ)),
        marker = FRect3D(Vec3f0(0), Vec3f0(8)),
        colormap = colors, 
        transparency = true, 
        shading= false)
    meshscatter!(ax2,positions, color = vec(abs2ψ), colorrange = (minimum(abs2ψ),maximum(abs2ψ)),
        marker = FRect3D(Vec3f0(0), Vec3f0(8)), 
        colormap = cmap_alpha, 
        transparency = true,  
        shading= false)
    
    cbar1 = Colorbar(fig, limits = (minimum(abs2ψ),maximum(abs2ψ)), colormap = colors, label = "color range", height = Relative(0.5))
    cbar2 = Colorbar(fig, limits = (minimum(abs2ψ),maximum(abs2ψ)), colormap = cmap_alpha, label = "tranceparent color range", height = Relative(0.5))
    
    xlims!(ax1,-L-1,L+1)
    ylims!(ax1,-L-1,L+1)
    zlims!(ax1,-L-1,L+1)
    xlims!(ax2,-L-1,L+1)
    ylims!(ax2,-L-1,L+1)
    zlims!(ax2,-L-1,L+1)
    
    fig[1,2] = cbar1
    fig[2,2] = cbar2
    fig
    save("test.png", fig)
end

```

 ![test](https://global.discourse-cdn.com/julialang/original/3X/8/4/840a56be49f3b50f836abed15c519557e3f04286.jpeg)

Is there any way to shorten the distance between fig[1,1] and fig[1,2] (also fig[2,1] and fig[2,2]) ?
