diff --git a/src/arg_desc.jl b/src/arg_desc.jl index c8224d01..c6947abd 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -178,6 +178,9 @@ const _arg_desc = KW( :minorgridlinewidth => "Number. Width of the minor grid lines (in pixels)", :tick_direction => "Symbol. Direction of the ticks. `:in`, `:out` or `:none`", :showaxis => "Bool, Symbol or String. Show the axis. `true`, `false`, `:show`, `:hide`, `:yes`, `:no`, `:x`, `:y`, `:z`, `:xy`, ..., `:all`, `:off`", -:widen => "Bool. Widen the axis limits by a small factor to avoid cut-off markers and lines at the borders. Defaults to `true`.", +:widen => """ + Bool or :auto. Widen the axis limits by a small factor to avoid cut-off markers and lines at the borders. + Defaults to `:auto`, which widens unless limits were manually set. + """, :draw_arrow => "Bool. Draw arrow at the end of the axis.", ) diff --git a/src/args.jl b/src/args.jl index 06f38943..965f3fc2 100644 --- a/src/args.jl +++ b/src/args.jl @@ -476,7 +476,7 @@ const _axis_defaults = KW( :minorticks => false, :minorgrid => false, :showaxis => true, - :widen => true, + :widen => :auto, :draw_arrow => false, ) diff --git a/src/axes.jl b/src/axes.jl index 3487a98f..647c4b2c 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -504,6 +504,11 @@ end const _widen_seriestypes = (:line, :path, :steppre, :stepmid, :steppost, :sticks, :scatter, :barbins, :barhist, :histogram, :scatterbins, :scatterhist, :stepbins, :stephist, :bins2d, :histogram2d, :bar, :shape, :path3d, :scatter3d) function default_should_widen(axis::Axis) + if axis[:widen] isa Bool + return axis[:widen] + end + # automatic behavior: widen if limits aren't specified and series type is appropriate + (is_2tuple(axis[:lims]) || axis[:lims] == :round) && return false for sp in axis.sps for series in series_list(sp) if series.plotattributes[:seriestype] in _widen_seriestypes @@ -559,7 +564,7 @@ function axis_limits(sp, letter, should_widen = default_should_widen(sp[Symbol(l else amin, amax end - elseif should_widen && axis[:widen] + elseif should_widen widen(amin, amax, axis[:scale]) elseif lims == :round round_limits(amin,amax) diff --git a/test/test_axes.jl b/test/test_axes.jl index 78ca09ac..b1bc4139 100644 --- a/test/test_axes.jl +++ b/test/test_axes.jl @@ -35,6 +35,18 @@ end @testset "Axis limits" begin pl = plot(1:5, xlims=:symmetric, widen = false) @test Plots.xlims(pl) == (-5, 5) + + pl = plot(1:3) + @test Plots.xlims(pl) == Plots.widen(1,3) + + pl = plot(1:3, xlims=:round) + @test Plots.xlims(pl) == (1, 3) + + pl = plot(1:3, xlims=(1,5)) + @test Plots.xlims(pl) == (1, 5) + + pl = plot(1:3, xlims=(1,5), widen=true) + @test Plots.xlims(pl) == Plots.widen(1, 5) end @testset "3D Axis" begin