Skip to content

Commit

Permalink
fix single :auto in xlims or ylims (#4378)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg authored Sep 26, 2022
1 parent 30c667e commit 89c68d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,11 @@ function round_limits(amin, amax, scale)
amin, amax
end

process_limits(lims::Tuple{<:Real,<:Real}) = lims
process_limits(lims::Tuple{<:Union{Symbol,Real},<:Union{Symbol,Real}}) = lims
process_limits(lims::Symbol) = lims
process_limits(lims::AVec) =
length(lims) == 2 && all(x isa Real for x in lims) ? Tuple(lims) : nothing
length(lims) == 2 && all(map(x -> x isa Union{Symbol,Real}, lims)) ? Tuple(lims) :
nothing
process_limits(lims) = nothing

warn_invalid_limits(lims, letter) = @warn """
Expand All @@ -611,13 +612,15 @@ function axis_limits(
has_user_lims = lims isa Tuple
if has_user_lims
lmin, lmax = lims
if lmin === :auto
elseif isfinite(lmin)
if lmin isa Number && isfinite(lmin)
amin = lmin
else
lmin === :auto || @warn "Invalid min limit" lmin
end
if lmax === :auto
elseif isfinite(lmax)
if lmax isa Number && isfinite(lmax)
amax = lmax
else
lmax === :auto || @warn "Invalid max $(letter)limit" lmax
end
end
if lims === :symmetric
Expand Down
20 changes: 20 additions & 0 deletions test/test_axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ end
)
@test plims == Plots.widen(1, 5)
end

@testset "JuliaPlots/Plots.jl/issues/4379" begin
for ylims in ((-5, :auto), [-5, :auto])
pl = plot([-2, 3], ylims = ylims, widen = false)
@test Plots.ylims(pl) == (-5.0, 3.0)
end
for ylims in ((:auto, 4), [:auto, 4])
pl = plot([-2, 3], ylims = ylims, widen = false)
@test Plots.ylims(pl) == (-2.0, 4.0)
end

for xlims in ((-3, :auto), [-3, :auto])
pl = plot([-2, 3], [-1, 1], xlims = xlims, widen = false)
@test Plots.xlims(pl) == (-3.0, 3.0)
end
for xlims in ((:auto, 4), [:auto, 4])
pl = plot([-2, 3], [-1, 1], xlims = xlims, widen = false)
@test Plots.xlims(pl) == (-2.0, 4.0)
end
end
end

@testset "3D Axis" begin
Expand Down

0 comments on commit 89c68d9

Please sign in to comment.