Makie: is it possible to draw major and minor ticks on all four axes?

I can not find the solution from the doc. Note that I do not mean twin axes. I just want to pair the ticks for left and right axes, and bottom and top axes, respectively. Thanks!

I never implemented those, no. But you can add them with a little bit of extra work. You can examine ax.elements[:xaxis] for example, it has observables that hold the tick positions, you just need to mirror them over to the other side and add them via linesegments

But this seems a basic functionality for a plotting software? Python’s matplotlib do it with a simple option: xtick.top = True and ytick.right = True. And a bunch of physics journal seems to prefer such axis layout.

Yes it could be useful, we always appreciate PRs for missing features

1 Like

Just wanted to leave a workaround I found while running into this same problem. One can get ticks on all sides by creating a linked axis on top ticking top and right.

using Makie
using CairoMakie

f = Figure()
ga = f[1, 1] = GridLayout()
axis = Axis(ga[1,1])

scatter!(axis,rand(10),rand(10))

# create axis on top to get ticks on all sides
axis_ticks = Axis(ga[1,1], yaxisposition = :right, xaxisposition = :top, rightspinevisible = false, leftspinevisible = false, topspinevisible = false, bottomspinevisible = false)
linkaxes!(axis, axis_ticks)
hidexdecorations!(axis_ticks,ticks=false, minorticks=false)
hideydecorations!(axis_ticks,ticks=false, minorticks=false)

save("example.png",f)

Which gives me:

Would be great to have the possibility to set yaxisposition and xaxisposition to :both to specify this without needing an extra axis. Never gone into the Makie source code but might try to have a jab at it and submit a PR.

This feature exists now: https://docs.makie.org/stable/examples/blocks/axis/index.html#mirrored_ticks

f = Figure()
Axis(f[1, 1],
    xticks = 0:10,
    yticks = 0:10,
    xticksmirrored = true,
    yticksmirrored = true,
    xminorticksvisible = true,
    yminorticksvisible = true,
    xminortickalign = 1,
    yminortickalign = 1,
    xtickalign = 1,
    ytickalign = 1,
)
f

3 Likes

Excellent!

much better than my dirty hack

Although it seems to have an issue when using layouts and rowsize!

using Makie
using CairoMakie

f = Figure()
ga = f[1, 1] = GridLayout()
axtop = Axis(ga[1,1],xticksmirrored = true, yticksmirrored = true, xtickalign=1,ytickalign=1)
axbottom = Axis(ga[2,1],xticksmirrored = true, yticksmirrored = true, xtickalign=1,ytickalign=1)

rowsize!(ga,1,Auto(0.3))

save("example.png",f)

f

This one seems to place the top ticks for the bottom plot in the position where the axis would be absent rowsize! (and indeed it works if one does not use rowsize!)

1 Like

Hm seems like updating the ticks is still a little buggy, I think there’s already an issue about that

1 Like

Thanks for updating this! It is very handy.