From 11e9eb3aa354a5ea07e608cb9d5c35bdbe19efdb Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sun, 23 Apr 2017 20:30:48 +0200 Subject: [PATCH] allow Int as input type for the ticks attribute to set the desired number of ticks --- src/axes.jl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/axes.jl b/src/axes.jl index 7af2d7c5..dae525c3 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -188,6 +188,23 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing) k_min = 5, # minimum number of ticks k_max = 8, # maximum number of ticks )[1] + elseif typeof(ticks) <: Int + # only return ticks within the axis limits + filter( + ti -> sf(amin) <= ti <= sf(amax), + optimize_ticks( + sf(amin), + sf(amax); + # TODO: find a better configuration to return the chosen number + # of ticks + k_min = ticks + 1, # minimum number of ticks + k_max = ticks + 2, # maximum number of ticks + k_ideal = ticks + 2, + # `strict_span = false` rewards cases where the span of the + # chosen ticks is not too much bigger than amin - amax: + strict_span = false, + )[1] + ) else map(sf, filter(t -> amin <= t <= amax, ticks)) end @@ -226,7 +243,7 @@ function get_ticks(axis::Axis) elseif ticks == :auto # compute optimal ticks and labels optimal_ticks_and_labels(axis) - elseif typeof(ticks) <: AVec + elseif typeof(ticks) <: Union{AVec, Int} # override ticks, but get the labels optimal_ticks_and_labels(axis, ticks) elseif typeof(ticks) <: NTuple{2}