Makie.jl icon indicating copy to clipboard operation
Makie.jl copied to clipboard

volume plot of negative values fails

Open alexriss opened this issue 2 years ago • 1 comments

A volume plot with negative values does not seem to work.

Consider the following example (adapted from Beautiful Makie):

using GLMakie # same with WGLMakie
let
	  x = y = z = 1:10
	  f(x, y, z) = x^2 + y^2 + z^2
	  vol = [-f(ix, iy, iz) for ix in x, iy in y, iz in z]
	  fig, ax, _ = volume(vol; colorrange = (minimum(vol), maximum(vol)), transparency = true,
	     figure = (; resolution = (1200, 800)),  axis = (; type = Axis3))
	  display(fig)
end

I get a single-colored volume plot:

It works for positive values:

using GLMakie # same with WGLMakie
let
	  x = y = z = 1:10
	  f(x, y, z) = x^2 + y^2 + z^2
	  vol = [f(ix, iy, iz) for ix in x, iy in y, iz in z]   # removed the `-` here
	  fig, ax, _ = volume(vol; colorrange = (minimum(vol), maximum(vol)), transparency = true,
	     figure = (; resolution = (1200, 800)),  axis = (; type = Axis3))
	  display(fig)
end

GLMakie v0.5.5

alexriss avatar Mar 22 '22 22:03 alexriss

Interestingly, this issue seems to be fixed by normalizing the data manually to the 0 .. 1 range instead of using the colorrange argument:

using GLMakie
let
             x = y = z = range(1.0,10.0,length=11)
             f(x, y, z) = x^2 + y^2 + z^2
             vol = [-f(ix, iy, iz) for ix in x, iy in y, iz in z]
             vol .-= minimum(vol)
             vol ./= maximum(vol)
             fig, ax, _ = volume(vol; transparency = true, figure = (; resolution = (1200, 800)),  axis = (; type = Axis3))
             display(fig)
end

Note: I had to replace the coordinate ranges by floating point values to make the in-place normalization work.

jkrimmer avatar Jul 22 '22 14:07 jkrimmer