diff --git a/src/axes.jl b/src/axes.jl index 0a39576f..8b2836dc 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -172,7 +172,7 @@ function optimal_ticks_and_labels(ticks, alims, scale, formatter) scaled_ticks = optimize_ticks( sf(amin), sf(amax); - k_min = scale in _logScales ? 2 : 4, # minimum number of ticks + k_min = scale ∈ _logScales ? 2 : 4, # minimum number of ticks k_max = 8, # maximum number of ticks scale = scale, )[1] @@ -352,23 +352,23 @@ function get_minor_ticks(sp, axis, ticks) ticks = [ticks[1] - first_step/ratio; ticks; ticks[end] + last_step*ratio] # Default to 9 intervals between major ticks for log10 scale and 5 intervals otherwise. - n_default = (scale === :log10) ? 9 : 5 + n_default = (scale == :log10) ? 9 : 5 n = typeof(axis[:minorticks]) <: Integer && axis[:minorticks] > 1 ? axis[:minorticks] : n_default - is_log_scale = scale in _logScales - base = is_log_scale ? _logScaleBases[scale] : nothing - sub = is_log_scale ? round(Int, log(ratio) / log(base)) : nothing + is_log_scale = scale ∈ _logScales + base = get(_logScaleBases, scale, nothing) + exp = is_log_scale ? round(Int, log(base, ratio)) : nothing minorticks = typeof(ticks[1])[] for (i, hi) in enumerate(ticks[2:end]) lo = ticks[i] if isfinite(lo) && isfinite(hi) && hi > lo if is_log_scale - for j in 1:sub - lo_ = lo * base^(j - 1) + for e in 1:exp + lo_ = lo * base^(e - 1) hi_ = lo_ * base step = (hi_ - lo_) / n append!(minorticks, collect( - lo_ + (j > 1 ? 0 : step) : step : hi_ - (j < sub ? 0 : step / 2) + lo_ + (e > 1 ? 0 : step) : step : hi_ - (e < exp ? 0 : step / 2) )) end else @@ -512,12 +512,12 @@ end # ------------------------------------------------------------------------- # push the limits out slightly -function widen(lmin, lmax, scale = :identity) +function widen(lmin, lmax, scale=:identity) f, invf = RecipesPipeline.scale_func(scale), RecipesPipeline.inverse_scale_func(scale) span = f(lmax) - f(lmin) # eps = NaNMath.max(1e-16, min(1e-2span, 1e-10)) eps = NaNMath.max(1e-16, 0.03span) - invf(f(lmin)-eps), invf(f(lmax)+eps) + invf(f(lmin) - eps), invf(f(lmax) + eps) end # figure out if widening is a good idea. @@ -539,10 +539,11 @@ function default_should_widen(axis::Axis) false end -function round_limits(amin,amax) - scale = 10^(1-round(log10(amax - amin))) - amin = floor(amin*scale)/scale - amax = ceil(amax*scale)/scale +function round_limits(amin, amax, scale) + base = get(_logScaleBases, scale, 10.) + factor = base^(1 - round(log(base, amax - amin))) + amin = floor(amin * factor) / factor + amax = ceil(amax * factor) / factor amin, amax end @@ -579,7 +580,7 @@ function axis_limits(sp, letter, should_widen = default_should_widen(sp[Symbol(l if axis[:letter] == :x amin, amax = 0, 2pi elseif lims == :auto - #widen max radius so ticks dont overlap with theta axis + # widen max radius so ticks dont overlap with theta axis 0, amax + 0.1 * abs(amax - amin) else amin, amax @@ -587,12 +588,15 @@ function axis_limits(sp, letter, should_widen = default_should_widen(sp[Symbol(l elseif should_widen widen(amin, amax, axis[:scale]) elseif lims == :round - round_limits(amin,amax) + round_limits(amin, amax, axis[:scale]) else amin, amax end - if !has_user_lims && consider_aspect && letter in (:x, :y) && !(sp[:aspect_ratio] in (:none, :auto) || RecipesPipeline.is3d(:sp)) + if ( + !has_user_lims && consider_aspect && letter in (:x, :y) && + !(sp[:aspect_ratio] in (:none, :auto) || RecipesPipeline.is3d(:sp)) + ) aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1 plot_ratio = height(plotarea(sp)) / width(plotarea(sp)) dist = amax - amin @@ -728,6 +732,7 @@ function axis_drawing_info(sp, letter) invf = RecipesPipeline.inverse_scale_func(oax[:scale]) add_major_or_minor_segments(ticks, grid, segments, factor, cond) = begin + ticks === nothing && return if cond tick_start, tick_stop = if sp[:framestyle] == :origin t = invf(f(0) + factor * (f(oamax) - f(oamin))) @@ -853,6 +858,7 @@ function axis_drawing_info_3d(sp, letter) ga0, ga1 = sp[:framestyle] in (:origin, :zerolines) ? (namin, namax) : (na0, na1) add_major_or_minor_segments(ticks, grid, segments, factor, cond) = begin + ticks === nothing && return if cond tick_start, tick_stop = if sp[:framestyle] == :origin t = invf(f(0) + factor * (f(namax) - f(namin)))