Combining 3D scatter plot with a 3D heat map

I am trying to create a 3D visualization of a laser passing through a cloud of atoms. I attempted to do this using the GLVisualize backend for Plots.jl in the following way:

using GLVisualize, Plots
x = linspace(-10, 10, 100)
a = randn(100, 3) # atom positions
b = permutedims(exp(-x.^2).*(exp(-x.^2).').*ones(1, 1, 100), [1, 3, 2])   # laser beam
plot(b) # plot laser
scatter!(a[:, 1], a[:, 2], a[:, 3], color=:white, alpha=0.6) # plot atoms

This creates a nice visualization of the laser, however, it seems that the scatter plot points that would depict the atoms never show up. Does anyone have an idea of how to do this?

b is a volume and the default color map that is applied to it doesn’t come with transparent values so the whole volume renders as opaque.
You need to make sure to map 0 in b to a transparent color.
This works:

cmap = Plots.ColorGradient(:inferno)
cmap.colors[1] = RGBA(0.,0.0,0.0,0.0)
plot(b, color = cmap)

You might also want to have a gradient in the transparency as well :wink:


Thanks for that, and also for the great package! After a bit of playing around I get a reasonable result using:

cmap = colormap("Reds")
plot(b, color=cmap, alpha=0.5)
scatter!(a[:, 1], a[:, 2], a[:, 3], color=:black, alpha=0.1, xlims = (-10,10), ylims = (-10,10), zlims = (-10,10))

One thing I don’t understand is that if I raise alpha above 0.5 in the volume plot the atoms never appear.

1 Like

Yeah sorry about that… Transparency is a bit tricky and I hard coded some value to turn on depth testing…
This works great for my anti aliasing, but is really terrible for general transparency.
I think I have figured out how to do this better in the future… Just need to integrate it :wink:

1 Like