3d Plots - change axis intersection // inverse axis

I have a 3d plot:

using Plots

x = [0,0,0,1,1,1,2,2,2]
y=[0,1,2,0,1,2,0,1,2]
z = 10*rand(9) .+ 2*collect(1:9)

plot(x,y,z, st=:surface,camera = (60,15))

axes intersect at:

How can I change it so:
z and y on min z and max y. y and x at min y and min z

plot(x,y,z, st=:surface,camera = (60,15), yflip = true)

flips whole graph, not just axis, while axes are connected at the same points.

I’m not sure what you are trying to do, but I think you want to rotate the plot more, so that the axes go behind the plot. Just playing around in Pluto, I found that the plot would not update angles beyond (0, 90). In the GIF below, I tried pushing the angle to -10 or 100:

Dec-02-2020 23-24-36

Is that your issue?

1 Like

Nope, I want to inverse Y axis:
YZ intersection would be (z = 0, y = 2)
YX intersection would be (y = 0, x = 0)

You want to change the origin of the axes?

Yes. Specifically of Y axis

So you want the axes to not intersect at the same point?

I want Y and X have origin in the same point (0,0,min(z))

1 Like

Oh I see now! A nice scketch is worth a thousand words! Not sure you can do that if yflip does not work. have you tried flipping your data and the tick labels manually?

I could make data negative, and make ticks as strings (without minus). But this must be simplier.

x =- [0,0,0,1,1,1,2,2,2]
y=  [0,1,2,0,1,2,0,1,2]
z = 10*rand(9) .+ 2*collect(1:9)

plot(x,y,z, st=:surface,camera = (85,15),xticks = ([-2,-1,0], [2,1,0]) )

This works, but I am disappointed.

2 Likes

How does one open a feature request? Without the ability to change where axes intersect, Julia decides that I don’t need to see the axes:


and after adding camera=(-45, atand(1 / √2)):

Edit: Came up with a hack

function rotate_negative_45_degrees!(surface_plot)
    # The GR backend cannot properly display the axes if you decide to rotate
    # the camera -45 degrees. This wouldn't be so bad if it had a way of
    # manually setting the spine positions a la matplotlib, but it doesn't.

    # Swap the axis labels
    temp = surface_plot[1][:xaxis][:guide]
    xlabel!(surface_plot, surface_plot[1][:yaxis][:guide])
    ylabel!(surface_plot, temp)

    # Swap the ticks
    temp = xticks(surface_plot)[1]
    xticks!(surface_plot, yticks(surface_plot)[1])
    yticks!(surface_plot, temp)

    # Transform data appropriately
    xticks!(surface_plot, (xticks(surface_plot)[1][1], reverse(xticks(surface_plot)[1][2])))
    surface_plot[1][1][:z] = Surface(reverse(surface_plot[1][1][:z].surf', dims=2))
end

Linking related thread here.

1 Like