Respect :widen when passing :lims (#3552)
* Respect :widen when passing :lims Previously, the limits were not widened when passing a tuple or :round to lims (ignoring the widen argument). Fixes #3339 * 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 * Update test/test_axes.jl Co-authored-by: Simon Christ <SimonChrist@gmx.de> * fix docs for lims and widen interaction * Update .zenodo.json * Update test/test_axes.jl xlims != ylims Co-authored-by: Simon Christ <SimonChrist@gmx.de> Co-authored-by: Simon Christ <SimonChrist@gmx.de>
This commit is contained in:
parent
5330776040
commit
019a742c84
@ -688,6 +688,10 @@
|
||||
"name": "@t-bltg",
|
||||
"type": "Other"
|
||||
}
|
||||
{
|
||||
"name": "Fred Callaway",
|
||||
"type": "Other"
|
||||
}
|
||||
],
|
||||
"upload_type": "software"
|
||||
}
|
||||
|
||||
@ -141,6 +141,7 @@ const _arg_desc = KW(
|
||||
NTuple{2,Number} or Symbol. Force axis limits. Only finite values are used (you can set only the right limit with `xlims = (-Inf, 2)` for example).
|
||||
`:round` widens the limit to the nearest round number ie. [0.1,3.6]=>[0.0,4.0]
|
||||
`:symmetric` sets the limits to be symmetric around zero.
|
||||
Set widen=true to widen the specified limits (as occurs when lims are not specified).
|
||||
""",
|
||||
:ticks => "Vector of numbers (set the tick values), Tuple of (tickvalues, ticklabels), or `:auto`",
|
||||
:scale => "Symbol. Scale of the axis: `:none`, `:ln`, `:log2`, `:log10`",
|
||||
@ -177,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,
|
||||
)
|
||||
|
||||
|
||||
14
src/axes.jl
14
src/axes.jl
@ -504,17 +504,19 @@ 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)
|
||||
should_widen = false
|
||||
if !(is_2tuple(axis[:lims]) || axis[:lims] == :round)
|
||||
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
|
||||
should_widen = true
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
should_widen
|
||||
false
|
||||
end
|
||||
|
||||
function round_limits(amin,amax)
|
||||
@ -562,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.05,2.0,2.95], ylims=:round)
|
||||
@test Plots.ylims(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