Makie: adjusting axis scale / limits in 3D

Hello,

I would like to use very non-isotropic axis scales in 3D scatter plots. I can set the limits of the axis, but couldn’t find a working way of changing the data scaling in x/y/z (so that the plot is not overly stretched in one dimension). Is there any easy way (without scaling the data itself)? I tried modifying the “scale” attribute of the Axis3D, to no avail.

minimal example:

using Makie

R = 4.0
x = randn(100_000)
y = randn(100_000)
z = randn(100_000) * R

lim = FRect3D((-4,-4,-4*R),(8,8,8*R))
scatter(x, y, z, markersize = 0.001, transparency=true, alpha=0.1, limits=lim)

how do I scale in z-dimension by 1/R ?

using Makie

R = 4.0
x = randn(100_000)
y = randn(100_000)
z = randn(100_000) * R

lim = FRect3D((-4,-4,-4R),(8,8,8R))
scene = scatter(x, y, z, markersize = 0.001, transparency=true, alpha=0.1, limits=lim)
scale!(scene, 1, 1, 1/R)

Or 

scene = scatter(x, y, z, markersize = 0.001, transparency=true, alpha=0.1, limits=lim, scale = (1.0, 1.0, 1/R)

Great, thanks!

Is there also a way to control the pivot point for mouse rotation?

1 Like

Yeah, via panning with the middle mouse button…
You can also set it via:

update_cam!(scene, eyeposition, lookat) # lookat == pivot point

As you can see in the source, you can get the current eyeposition via cameracontrols(scene).eyeposition[]

Hi and thanks again for the answer!

As I’m coming back to this, I’m having a related problem with the text font size being in data units. If I try to scale that, it fails at larger values, producing graphical glitches… maybe because textsize is an Integer? Or it could just be my GPU (Integrated Intel Iris Pro 5200), I don’t know.

example:

using Makie

function testTicks(f)
    x = [0,1,0,1,0,1,0,1]
    y = [0,0,1,1,0,0,1,1]
    z = [0,0,0,0,1,1,1,1] .* f
    s = Scene(resolution=(500,400))
    scatter!(s,x,y,z, markersize=f/50)
    Makie.scale!(s,(f,f,1))
    s[:limits] = FRect3D((0,0,0),(1,1,1*f))
    s[Axis][:ticks,:textsize] = (f*5,f*5,f*5)
    return s
end

while testTicks(1e6) works for me, I’m seeing random gray triangles with ~1e8 or above.
Any advice, besides rescaling the data and manually setting the tick positions / labels?

Resurrecting this Makie thread as I cannot get the axes limits to work in 3D surface plots by using the keyword limits as indicated above. Running Julia Version 1.6.0-beta1.0 on Win10 VS Code.
PS: the following workaround sets NaNs outside the z-limits but the plot edges are not properly shaved… Is there any option to smooth the edges?

using Makie
x = y = LinRange(-2, 2, 200)
f(x,y) = -(x^2 + y^2)
scene = Scene(resolution = (1000, 1000))
zlimf(x,y) = -2 < (z = f(x,y)) < -0.5 ? z : NaN   # z-limiting function (workaround)
surface!(scene, x, y, zlimf)

2 Likes