Makie.jl: Axis3() reverse limits don't work

I am attempting to create a plot that has x = longitude, y=latitude, and z= depth. Since z = 0 is the surface, I need to reverse the limits (e.g. zlims!() ). Although this works perfectly for Axes(), it does not for Axis3().

From the manual

limits!(ax::Axis3, x1, x2, y1, y2, z1, z2)
Set the axis x-limits to x1 and x2 and the y-limits to y1 and y2.
If limits are ordered high-low, this reverses the axis orientation.

Instead, when I try to get my z-axis to be reversed, I get an error:
Invalid z-limits as zlims[1] <= zlims[2] is not met for (100.0f0, 0.0f0).

I get this error for any limits I attempt to set in Axis3, whether x,y,or z.
I do not have this issue in regular 2D Axis() 2D plots where I can set the ylimits to be reversed…

I noticed that the ‘reverses’ have been commented out in xlims, ylims, and zlims in: Makie.jl/axis3d.jl at master · JuliaPlots/Makie.jl · GitHub

Was there a reason for this? Is there a better/more elegant way to reverse axes in Axis3()?

Thanks!

1 Like

I don’t know if I fully understand the issue. Could you just plot the negative values, redefining the axis ticks if necessary?

For example,

using GLMakie

# example data
xs = collect(0:1:10); ys = collect(0:1:6)
zs = [ 2 * x + .5 * y^2 for x ∈ xs, y ∈ ys ]

# function to reverse the z axis values
minuslabels(values) = [ "$(abs(v))" for v ∈ values ]

fig = Figure()
ax1 = Axis3(fig[1, 1], ztickformat = minuslabels, 
    viewmode = :fit)
surface!(ax1, xs, ys, -zs)

I think the reason that you can’t reverse the x and y axes as you would on a 2-dimensional plot is that this is achieved by rotating the plot with azimuth:

ax2 = Axis3(fig[1, 2], azimuth = .2pi, ztickformat = minuslabels, 
    viewmode = :fit)
surface!(ax2, xs, ys, -zs)

which has essentially reversed the x and y axes.

I thought elevation might do something similar for the z axis but it doesn’t seem to.

Reversed axes weren’t implemented so far for Axis3 but it should give a better error than what’s posted above.

Ah, that’s good.

I had been playing around with the azimuth value and had managed to obtain graphs with the appropriate orientation but it led to the axes being ‘on top’ rather than at the bottom of the 3d axes. That would not have been appropriate for anything but data exploration.

The example provided with the minuslabels function above solves this problem so that is wonderful, and I am very glad that the error message has been updated to better reflect the issue. I wonder would it be possible to add the above solution to the documentation though since I can’t be the only person who sometimes wants to reverse a third axis?

Thanks again everyone, I very much appreciate the input.

1 Like

The best way forward would probably be to implement reversal correctly rather than fake this via tick tweaking. I’m always hesitant to put hacks into the documentation because they tend to stick even more then

1 Like

That’s how I came across this question.

I was surprised there weren’t more questions about it which made me wonder if there’s a trick that I haven’t come across yet.