Can I change axis position in Plots

I’m trying to change an axis position. For example make the xaxis at y=0 instead of y=-3 here

using Plots
f(x)=x-3
plot(f,0,5,xlabel=“x”,ylabel= “y”)

I tried the documentation for Plots but I didn’t find a possible option in axis attributes
https://docs.juliaplots.org/latest/generated/attributes_axis/

maybe you want plot(f, 0, 5, xlabel = "x", ylabel = "y", framestyle = :zerolines)?

2 Likes

This is good but what I really want is to control the position of the axis not nesccarilly keep it at y=0.

1 Like

There is no way to do this rather than modifying the backend plot object after the fact or use the etra_kwargs mechanism, thats currently only implemented for the pgfplotsx backend

1 Like

What about this:

f(x)=x-3
plot(f, 0, 5, xlabel = "x", ylabel = "y", ylims=(0,Inf), xlims=(3,Inf), legend=:topleft)

test

But that didn’t shift the x-axis, it is still at y=0

For example make the xaxis at y=0

Hmmm, I suppose I don’t understand what the goal is then. Can you post an example of an output you’re trying to achieve?

I used AxisOrigin in Mathemtica to position the x-axis at y=3 and this is the output
Screenshot from 2020-05-07 20-23-25

I see. A quick (and dirty) way would be to just cheat by manually specifying the tick labels, like this:

plot(
    f, 0, 5,
    legend=false, 
    framestyle=:origin,
    yticks=(-3:3, ["$i" for i in 0:6])
)

test

4 Likes

I like it :smile: Thank you!

1 Like

I find that a pretty confusing graph…

5 Likes

Would It be possible to do something like this on a 3D plot? GR has decided I don’t need to see the axes if I want to rotate the plot:

Edit: This reply essentially became a duplicate of this other reply. See visuals and workaround there.

Check workaround here.

1 Like