Makie aspect ratio 3D plot

When plotting into an LScene and by using an Axis, the output figure is always rescaled into the data limits, making sometimes hard to see things, if one of the variables is too large or to low.

using GLMakie
fig = Figure(resolution = (600, 400)) 
ax = LScene(fig, scenekw = (camera = cam3d!, show_axis =true))
sphere = surface!(ax, 4*rand(100,100), 2*rand(100,100), 0.1*rand(100,100),  color = rand(100,100), 
    colormap = :hot, shading = false, transparency = true)
fig[1, 1] = ax


In some cases is nice[like below], but not always [most cases I would say].

I would like to be able to control the aspect_ratio in every direction, is that possible somehow?

related question: Issues with JuliaPlots aspect ratio in 3d
the zoom question there is also a problem in most of cases [a lot of white space].


Given the range of input data along each axis, if one wants to scale the output independently by 1x, 2x and 40x for example, along x-, y- and z-axis, I think this works:

scene = Scene(resolution = (600, 400))
scale!(scene, 1, 2, 40)
1 Like

For somewhat cubic plots regardless of limits in each direction, I usually do something like:

    lims = ((0, 100), (0, 4), (0, 150))
    xlims!(scene, lims[1])
    ylims!(scene, lims[2])
    zlims!(scene, lims[3])
    m = maximum(abs(x[2] - x[1]) for x in lims)
    a = [m / abs(x[2] - x[1]) for x in lims]
    scale!(scene, a...)
1 Like

Should give some real improvements for this situation!


in the example above using scale!(ax.scene, 100, 100, 2055) seems to give good aspect_ratios, however once you do that all fonts are distorted.


I’m running into the same aspect ratio problem. Is there a better solution to the aspect ratio problem now?

With Axis3 yes but that is more for final display of some data, not fully interactive exploration. You can only rotate around but for many things that’s enough

That worked. In case anybody else runs into this problem here are the details:

ax = Axis3(fig[1,1:2],viewmode = :fit)