Transparent plotting in Makie

BeautifulMakie is very helpful for 3D plotting.
But, in this volume with scatters, x,y,z, f(x,y,z) 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}]”. 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?

1 Like

You should take a look at contour(vol) instead of using a scatter :wink:
Also: volume

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?

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

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

1 Like

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 is what I want.
Normally, transparent areas would be painted black, but by adjusting the areas to be colored, they made them transparent.

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

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.
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!

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. :smiley: , anyhow… here is the plot, I hope it helps.

For completeness I also plotted other ways to plot the same data. See the full code as usual at volumeTransparent

3 Likes

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

@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

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