From cbbd4fd02933f05a460d6e8ebcf2619c99e60b5f Mon Sep 17 00:00:00 2001 From: Will Grant Date: Wed, 6 Jun 2018 11:20:05 +1000 Subject: [PATCH 1/2] allow automatic widening of the axis limits to the next power of 10 with xlim/ylim = :round --- src/axes.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/axes.jl b/src/axes.jl index c873086e..f32d0ade 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -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 From 91ed04ff83c6af7d36f114b827de9556739b1d6a Mon Sep 17 00:00:00 2001 From: Will Grant Date: Wed, 6 Jun 2018 18:44:07 +1000 Subject: [PATCH 2/2] update documentation in arg_desc with round limits option --- src/arg_desc.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arg_desc.jl b/src/arg_desc.jl index 199190db..a45ba315 100644 --- a/src/arg_desc.jl +++ b/src/arg_desc.jl @@ -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.",