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",
|
"name": "@t-bltg",
|
||||||
"type": "Other"
|
"type": "Other"
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
"name": "Fred Callaway",
|
||||||
|
"type": "Other"
|
||||||
|
}
|
||||||
],
|
],
|
||||||
"upload_type": "software"
|
"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).
|
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]
|
`: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.
|
`: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`",
|
:ticks => "Vector of numbers (set the tick values), Tuple of (tickvalues, ticklabels), or `:auto`",
|
||||||
:scale => "Symbol. Scale of the axis: `:none`, `:ln`, `:log2`, `:log10`",
|
: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)",
|
:minorgridlinewidth => "Number. Width of the minor grid lines (in pixels)",
|
||||||
:tick_direction => "Symbol. Direction of the ticks. `:in`, `:out` or `:none`",
|
: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`",
|
: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.",
|
:draw_arrow => "Bool. Draw arrow at the end of the axis.",
|
||||||
)
|
)
|
||||||
|
|||||||
@ -476,7 +476,7 @@ const _axis_defaults = KW(
|
|||||||
:minorticks => false,
|
:minorticks => false,
|
||||||
:minorgrid => false,
|
:minorgrid => false,
|
||||||
:showaxis => true,
|
:showaxis => true,
|
||||||
:widen => true,
|
:widen => :auto,
|
||||||
:draw_arrow => false,
|
:draw_arrow => false,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
20
src/axes.jl
20
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)
|
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)
|
function default_should_widen(axis::Axis)
|
||||||
should_widen = false
|
if axis[:widen] isa Bool
|
||||||
if !(is_2tuple(axis[:lims]) || axis[:lims] == :round)
|
return axis[:widen]
|
||||||
for sp in axis.sps
|
end
|
||||||
for series in series_list(sp)
|
# automatic behavior: widen if limits aren't specified and series type is appropriate
|
||||||
if series.plotattributes[:seriestype] in _widen_seriestypes
|
(is_2tuple(axis[:lims]) || axis[:lims] == :round) && return false
|
||||||
should_widen = true
|
for sp in axis.sps
|
||||||
end
|
for series in series_list(sp)
|
||||||
|
if series.plotattributes[:seriestype] in _widen_seriestypes
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
should_widen
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
function round_limits(amin,amax)
|
function round_limits(amin,amax)
|
||||||
@ -562,7 +564,7 @@ function axis_limits(sp, letter, should_widen = default_should_widen(sp[Symbol(l
|
|||||||
else
|
else
|
||||||
amin, amax
|
amin, amax
|
||||||
end
|
end
|
||||||
elseif should_widen && axis[:widen]
|
elseif should_widen
|
||||||
widen(amin, amax, axis[:scale])
|
widen(amin, amax, axis[:scale])
|
||||||
elseif lims == :round
|
elseif lims == :round
|
||||||
round_limits(amin,amax)
|
round_limits(amin,amax)
|
||||||
|
|||||||
@ -35,6 +35,18 @@ end
|
|||||||
@testset "Axis limits" begin
|
@testset "Axis limits" begin
|
||||||
pl = plot(1:5, xlims=:symmetric, widen = false)
|
pl = plot(1:5, xlims=:symmetric, widen = false)
|
||||||
@test Plots.xlims(pl) == (-5, 5)
|
@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
|
end
|
||||||
|
|
||||||
@testset "3D Axis" begin
|
@testset "3D Axis" begin
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user