Skip to content

Commit

Permalink
minorticks consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Nov 19, 2022
1 parent 1a4c45f commit b4c2ab9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 9 additions & 3 deletions src/axes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,17 @@ _transform_ticks(ticks::NTuple{2,Any}, axis) = (_transform_ticks(ticks[1], axis)

const DEFAULT_MINOR_TICKS = Ref(4)

function no_minor_ticks(axis)
(n_minor_ticks = axis[:minorticks]) === false && return true # must be tested with `===` since Bool <: Integer
n_minor_ticks (:none, nothing) && return true
(n_minor_ticks === :auto && !axis[:minorgrid]) && return true
false
end

function get_minor_ticks(sp, axis, ticks_and_labels)
(n_minor_ticks = axis[:minorticks]) === false && return # must be tested with `===` since Bool <: Integer
n_minor_ticks (:none, nothing) && return
(n_minor_ticks === :auto && !axis[:minorgrid]) && return nothing
no_minor_ticks(axis) && return

n_minor_ticks = axis[:minorticks]
ticks = first(ticks_and_labels)
length(ticks) < 2 && return

Expand Down
2 changes: 1 addition & 1 deletion src/backends/pgfplotsx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ function pgfx_axis!(opt::Options, sp::Subplot, letter)
axis[:minorgridalpha],
axis[:minorgridstyle],
),
if (mt = axis[:minorticks]) > 1 && typeof(mt) <: Integer || mt
if length(minor_ticks) > 0
"major tick length" => "0.1cm"
else
"major tick length" => "0"
Expand Down
7 changes: 4 additions & 3 deletions src/backends/pyplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1263,9 +1263,10 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
pyaxis."grid"(false)
end

if axis[:minorticks] > 1
if !no_minor_ticks(axis) && axis[:minorticks] <: Integer
pyaxis."set_minor_locator"(
PyPlot.matplotlib.ticker.AutoMinorLocator(axis[:minorticks]),
# NOTE: AutoMinorLocator expects a number of intervals == number of ticks + 1
PyPlot.matplotlib.ticker.AutoMinorLocator(axis[:minorticks] + 1),
)
pyaxis."set_tick_params"(
which = "minor",
Expand All @@ -1276,7 +1277,7 @@ function _before_layout_calcs(plt::Plot{PyPlotBackend})
end

if axis[:minorgrid]
axis[:minorticks] > 1 || ax."minorticks_on"() # Check if ticks were already configured
no_minor_ticks(axis) || ax."minorticks_on"() # Check if ticks were already configured
pyaxis."set_tick_params"(
which = "minor",
direction = axis[:tick_direction] === :out ? "out" : "in",
Expand Down

0 comments on commit b4c2ab9

Please sign in to comment.