From 16b9fc08ac154450e25f11877e5b517b81819002 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Tue, 27 Oct 2020 20:16:45 +0100 Subject: [PATCH 1/2] more regular automatic categorical ticks --- src/axes.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/axes.jl b/src/axes.jl index 944d724a..0ef3a3a7 100644 --- a/src/axes.jl +++ b/src/axes.jl @@ -227,8 +227,9 @@ function get_ticks(sp::Subplot, axis::Axis; update = true) if !isempty(dvals) # discrete ticks... n = length(dvals) - rng = if ticks == :auto - Int[round(Int,i) for i in range(1, stop=n, length=min(n,15))] + rng = if ticks == :auto && n > 15 + Δ = ceil(Int, n / 10) + Δ:Δ:n else # if ticks == :all 1:n end From 6cbdd696cd6ebfc6600d917b39d1dc362721beed Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 28 Oct 2020 21:59:05 +0100 Subject: [PATCH 2/2] add unit tests --- test/test_axes.jl | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_axes.jl b/test/test_axes.jl index 07db6102..db2cb8cd 100644 --- a/test/test_axes.jl +++ b/test/test_axes.jl @@ -12,3 +12,12 @@ end @test plot(1, axis=nothing)[1][:xaxis][:ticks] == [] @test plot(1, axis=nothing)[1][:yaxis][:ticks] == [] end # testset + +@testset "Categorical ticks" begin + p1 = plot('A':'M', 1:13) + p2 = plot('A':'Z', 1:26) + p3 = plot('A':'Z', 1:26, ticks = :all) + @test Plots.get_ticks(p1[1], p1[1][:xaxis])[2] == string.('A':'M') + @test Plots.get_ticks(p2[1], p2[1][:xaxis])[2] == string.('C':3:'Z') + @test Plots.get_ticks(p3[1], p3[1][:xaxis])[2] == string.('A':'Z') +end