fix when ticks is nothing - format - minor updates
This commit is contained in:
parent
ee316e2913
commit
68a56fee91
40
src/axes.jl
40
src/axes.jl
@ -172,7 +172,7 @@ function optimal_ticks_and_labels(ticks, alims, scale, formatter)
|
|||||||
scaled_ticks = optimize_ticks(
|
scaled_ticks = optimize_ticks(
|
||||||
sf(amin),
|
sf(amin),
|
||||||
sf(amax);
|
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
|
k_max = 8, # maximum number of ticks
|
||||||
scale = scale,
|
scale = scale,
|
||||||
)[1]
|
)[1]
|
||||||
@ -352,23 +352,23 @@ function get_minor_ticks(sp, axis, ticks)
|
|||||||
ticks = [ticks[1] - first_step/ratio; ticks; ticks[end] + last_step*ratio]
|
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.
|
# 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
|
n = typeof(axis[:minorticks]) <: Integer && axis[:minorticks] > 1 ? axis[:minorticks] : n_default
|
||||||
is_log_scale = scale in _logScales
|
is_log_scale = scale ∈ _logScales
|
||||||
base = is_log_scale ? _logScaleBases[scale] : nothing
|
base = get(_logScaleBases, scale, nothing)
|
||||||
sub = is_log_scale ? round(Int, log(ratio) / log(base)) : nothing
|
exp = is_log_scale ? round(Int, log(base, ratio)) : nothing
|
||||||
|
|
||||||
minorticks = typeof(ticks[1])[]
|
minorticks = typeof(ticks[1])[]
|
||||||
for (i, hi) in enumerate(ticks[2:end])
|
for (i, hi) in enumerate(ticks[2:end])
|
||||||
lo = ticks[i]
|
lo = ticks[i]
|
||||||
if isfinite(lo) && isfinite(hi) && hi > lo
|
if isfinite(lo) && isfinite(hi) && hi > lo
|
||||||
if is_log_scale
|
if is_log_scale
|
||||||
for j in 1:sub
|
for e in 1:exp
|
||||||
lo_ = lo * base^(j - 1)
|
lo_ = lo * base^(e - 1)
|
||||||
hi_ = lo_ * base
|
hi_ = lo_ * base
|
||||||
step = (hi_ - lo_) / n
|
step = (hi_ - lo_) / n
|
||||||
append!(minorticks, collect(
|
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
|
end
|
||||||
else
|
else
|
||||||
@ -512,12 +512,12 @@ end
|
|||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
# push the limits out slightly
|
# 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)
|
f, invf = RecipesPipeline.scale_func(scale), RecipesPipeline.inverse_scale_func(scale)
|
||||||
span = f(lmax) - f(lmin)
|
span = f(lmax) - f(lmin)
|
||||||
# eps = NaNMath.max(1e-16, min(1e-2span, 1e-10))
|
# eps = NaNMath.max(1e-16, min(1e-2span, 1e-10))
|
||||||
eps = NaNMath.max(1e-16, 0.03span)
|
eps = NaNMath.max(1e-16, 0.03span)
|
||||||
invf(f(lmin)-eps), invf(f(lmax)+eps)
|
invf(f(lmin) - eps), invf(f(lmax) + eps)
|
||||||
end
|
end
|
||||||
|
|
||||||
# figure out if widening is a good idea.
|
# figure out if widening is a good idea.
|
||||||
@ -539,10 +539,11 @@ function default_should_widen(axis::Axis)
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
function round_limits(amin,amax)
|
function round_limits(amin, amax, scale)
|
||||||
scale = 10^(1-round(log10(amax - amin)))
|
base = get(_logScaleBases, scale, 10.)
|
||||||
amin = floor(amin*scale)/scale
|
factor = base^(1 - round(log(base, amax - amin)))
|
||||||
amax = ceil(amax*scale)/scale
|
amin = floor(amin * factor) / factor
|
||||||
|
amax = ceil(amax * factor) / factor
|
||||||
amin, amax
|
amin, amax
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -579,7 +580,7 @@ function axis_limits(sp, letter, should_widen = default_should_widen(sp[Symbol(l
|
|||||||
if axis[:letter] == :x
|
if axis[:letter] == :x
|
||||||
amin, amax = 0, 2pi
|
amin, amax = 0, 2pi
|
||||||
elseif lims == :auto
|
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)
|
0, amax + 0.1 * abs(amax - amin)
|
||||||
else
|
else
|
||||||
amin, amax
|
amin, amax
|
||||||
@ -587,12 +588,15 @@ function axis_limits(sp, letter, should_widen = default_should_widen(sp[Symbol(l
|
|||||||
elseif should_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, axis[:scale])
|
||||||
else
|
else
|
||||||
amin, amax
|
amin, amax
|
||||||
end
|
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
|
aspect_ratio = isa(sp[:aspect_ratio], Number) ? sp[:aspect_ratio] : 1
|
||||||
plot_ratio = height(plotarea(sp)) / width(plotarea(sp))
|
plot_ratio = height(plotarea(sp)) / width(plotarea(sp))
|
||||||
dist = amax - amin
|
dist = amax - amin
|
||||||
@ -728,6 +732,7 @@ function axis_drawing_info(sp, letter)
|
|||||||
invf = RecipesPipeline.inverse_scale_func(oax[:scale])
|
invf = RecipesPipeline.inverse_scale_func(oax[:scale])
|
||||||
|
|
||||||
add_major_or_minor_segments(ticks, grid, segments, factor, cond) = begin
|
add_major_or_minor_segments(ticks, grid, segments, factor, cond) = begin
|
||||||
|
ticks === nothing && return
|
||||||
if cond
|
if cond
|
||||||
tick_start, tick_stop = if sp[:framestyle] == :origin
|
tick_start, tick_stop = if sp[:framestyle] == :origin
|
||||||
t = invf(f(0) + factor * (f(oamax) - f(oamin)))
|
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)
|
ga0, ga1 = sp[:framestyle] in (:origin, :zerolines) ? (namin, namax) : (na0, na1)
|
||||||
|
|
||||||
add_major_or_minor_segments(ticks, grid, segments, factor, cond) = begin
|
add_major_or_minor_segments(ticks, grid, segments, factor, cond) = begin
|
||||||
|
ticks === nothing && return
|
||||||
if cond
|
if cond
|
||||||
tick_start, tick_stop = if sp[:framestyle] == :origin
|
tick_start, tick_stop = if sp[:framestyle] == :origin
|
||||||
t = invf(f(0) + factor * (f(namax) - f(namin)))
|
t = invf(f(0) + factor * (f(namax) - f(namin)))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user