How to center the horizontal axis to the graph in Plots.jl

using NonlinearSolve, LinearAlgebra, Plots


g₂(u,p) = p[1]*Tridiagonal(fill(1,N₂), fill(-2,N₂+1), fill(1,N₂))*u - u.^3 - p[2]*u 

probg₂ = NonlinearProblem{false}(g₂, [0.1; fill(0.3, N₂-1); 0.1], [0.6, 1])
solver₂ = solve(probg₂, NewtonRaphson(), reltol = 1e-9) # solution is given as a vector

plot(solver₂, xlabel="x", ylabel="gₙ", linewidth=2, label=false, color="green", size=(450, 300))
scatter!(solver₂, xlabel="n", ylabel="gₙ", color="red", label=false, size=(450, 300))

The above code produces a vector of data points, solver_2, and then I plot those data points via the Plot.jl package and the scatter() function. See the below figure 1 for the plot resulting from the above code.

Question: How do I center the horizontal axis such that the peak of the graph is centered at the grid point n=0?

Attempt: Via the documentation here API · Plots I include xlims=(-7.5, 7.5), but this does not produce the desired result. See figure 2.

Fig 1:


Fig 2:

It looks like the graph peaks at n=8. So subtract 8 from your x axis variables. I do not know if there is an easy way to do this given that you are plotting using a convenience function rather than directly passing x and y values.

Sorry, I didn’t read that it actually is just plotting a vector. In this case you can do

plot((1:length(solver₂)) .- 8,solver₂, xlabel="x", ylabel="gₙ", linewidth=2, label=false, color="green", size=(450, 300))

In general, you’d want to have some function that finds the peak position rather than doing it visually like this.