Merge pull request #1547 from wfrgra/round_axis_limits

allow automatic widening of the axis limits to the next power of 10 …
This commit is contained in:
Daniel Schwabeneder 2018-06-06 21:48:52 +02:00 committed by GitHub
commit 30af3c7f8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -110,7 +110,7 @@ const _arg_desc = KW(
# axis args
:guide => "String. Axis guide (label).",
:lims => "NTuple{2,Number}. Force axis limits. Only finite values are used (you can set only the right limit with `xlims = (-Inf, 2)` for example).",
:lims => "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]",
:ticks => "Vector of numbers (set the tick values), Tuple of (tickvalues, ticklabels), or `:auto`",
:scale => "Symbol. Scale of the axis: `:none`, `:ln`, `:log2`, `:log10`",
:rotation => "Number. Degrees rotation of tick labels.",

View File

@ -441,6 +441,13 @@ function default_should_widen(axis::Axis)
should_widen
end
function round_limits(amin,amax)
scale = 10^(1-round(log10(amax - amin)))
amin = floor(amin*scale)/scale
amax = ceil(amax*scale)/scale
amin, amax
end
# using the axis extrema and limit overrides, return the min/max value for this axis
function axis_limits(axis::Axis, should_widen::Bool = default_should_widen(axis))
ex = axis[:extrema]
@ -471,6 +478,8 @@ function axis_limits(axis::Axis, should_widen::Bool = default_should_widen(axis)
end
elseif should_widen
widen(amin, amax)
elseif lims == :round
round_limits(amin,amax)
else
amin, amax
end