diff --git a/src/axes.jl b/src/axes.jl index 3d6236fb..c7a844ef 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -533,13 +533,20 @@ function axis_limits(sp, letter, should_widen = default_should_widen(sp[Symbol(l has_user_lims = (isa(lims, Tuple) || isa(lims, AVec)) && length(lims) == 2 if has_user_lims lmin, lmax = lims - if lmin != :auto && isfinite(lmin) + if lmin == :auto + elseif isfinite(lmin) amin = lmin end - if lmax != :auto && isfinite(lmax) + if lmax == :auto + elseif isfinite(lmax) amax = lmax end end + if lims == :symmetric + aval = max(abs(amin), abs(amax)) + amin = -aval + amax = aval + end if amax <= amin && isfinite(amin) amax = amin + 1.0 end diff --git a/test/test_axes.jl b/test/test_axes.jl index d981d21a..3f2170cb 100644 --- a/test/test_axes.jl +++ b/test/test_axes.jl @@ -31,3 +31,8 @@ end @test xticks(p) == yticks(p) == zticks(p) == [ticks1, ticks2] @test xticks(p[1]) == yticks(p[1]) == zticks(p[1]) == ticks1 end + +@testset "Axis limits" begin + pl = plot(1:5, xlims=:symmetric, widen = false) + @test Plots.xlims(pl) == (-5, 5) +end