Add default widen=:auto, which matches default before 43e9a342
* If widen is a Bool, it always determines whether widening occurs. * If widen is :auto (the defualt), widening occurs for appropriate seriestypes, unless lims were set manually
This commit is contained in:
parent
43e9a3426b
commit
7c4bc9e655
@ -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.",
|
||||
)
|
||||
|
||||
@ -476,7 +476,7 @@ const _axis_defaults = KW(
|
||||
:minorticks => false,
|
||||
:minorgrid => false,
|
||||
:showaxis => true,
|
||||
:widen => true,
|
||||
:widen => :auto,
|
||||
:draw_arrow => false,
|
||||
)
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user