Tick size in Plots.jl

I am having a very hard time trying to increase tick size in Plots.jl using gr(). Apparently there is no documentation on this either. Is there a way to do it?

The ticks’ thickness can be increased together with the axes - see manual section here. The axes labels fonts will increase too. To avoid that do:

using Plots; gr()
a = 2/3
Plots.scalefontsizes(a)
plot(sin, thickness_scaling = 1/a)
# Plots.reset_defaults()

I have found the solution regarding thickness, thanks! However, what I really want to increase is length, while keeping thickness fixed.

Check the simple ticks_length!() function herein to increase the ticks length:

function ticks_length!(;tl=0.02)
    p = Plots.current()
    xticks, yticks = Plots.xticks(p)[1][1], Plots.yticks(p)[1][1]
    xl, yl = Plots.xlims(p), Plots.ylims(p)
    x1, y1 = zero(yticks) .+ xl[1], zero(xticks) .+ yl[1]
    sz = p.attr[:size]
    r = sz[1]/sz[2]
    dx, dy = tl*(xl[2] - xl[1]), tl*r*(yl[2] - yl[1])
    plot!([xticks xticks]', [y1 y1 .+ dy]', c=:black, labels=false)
    plot!([x1 x1 .+ dx]', [yticks yticks]', c=:black, labels=false, xlims=xl, ylims=yl)
    return Plots.current()
end

# usage:
x = 0:0.01:2π; y = 0.1sin.(x)
plot(x,y)
ticks_length!()

plot(x,y)
ticks_length!(tl=0.015)
2 Likes

This is very handy! It’s unfortunate that the option is not implemented, but your fix certainly does the job for me. Thanks!

Edit: It doesn’t look like it works with 3D plots, though.

Is there any way to do the same for minor ticks? Replacing

Plots.xticks(p)

by

Plots.xminorticks(p)

does not work and the documentation is very sparse on that.

Just poking around in the source code here, to get the position of the minor xticks we can do:

using Plots; gr()
p = plot(size=(600,600), xlim=(1.1,5.3), ylim=(-0.1,3.0), xminorticks=2, yminorticks=2)
sp = first(p)
ticks = xticks(sp)
minor_ticks = Plots.get_minor_ticks(sp, sp[:xaxis], ticks)