axis limits = :symmetric (#2600)

* allow axis-lims = :symmetric

* remove show

* add test
This commit is contained in:
Simon Christ 2021-06-03 17:35:42 +02:00 committed by GitHub
parent 25b57cfb55
commit 6a62d96751
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -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 has_user_lims = (isa(lims, Tuple) || isa(lims, AVec)) && length(lims) == 2
if has_user_lims if has_user_lims
lmin, lmax = lims lmin, lmax = lims
if lmin != :auto && isfinite(lmin) if lmin == :auto
elseif isfinite(lmin)
amin = lmin amin = lmin
end end
if lmax != :auto && isfinite(lmax) if lmax == :auto
elseif isfinite(lmax)
amax = lmax amax = lmax
end end
end end
if lims == :symmetric
aval = max(abs(amin), abs(amax))
amin = -aval
amax = aval
end
if amax <= amin && isfinite(amin) if amax <= amin && isfinite(amin)
amax = amin + 1.0 amax = amin + 1.0
end end

View File

@ -31,3 +31,8 @@ end
@test xticks(p) == yticks(p) == zticks(p) == [ticks1, ticks2] @test xticks(p) == yticks(p) == zticks(p) == [ticks1, ticks2]
@test xticks(p[1]) == yticks(p[1]) == zticks(p[1]) == ticks1 @test xticks(p[1]) == yticks(p[1]) == zticks(p[1]) == ticks1
end end
@testset "Axis limits" begin
pl = plot(1:5, xlims=:symmetric, widen = false)
@test Plots.xlims(pl) == (-5, 5)
end