# Plot ticks at both top and bottom axis

**URL:** <https://discourse.julialang.org/t/plot-ticks-at-both-top-and-bottom-axis/9550>\
**Category:** Visualization\
**Tags:** plotting, plots\
**Created:** [March 6, 2018, 9:38pm UTC](https://discourse.julialang.org/t/plot-ticks-at-both-top-and-bottom-axis/9550 "2018-03-06T21:38:45Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Pablo\_Marchant](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pablo_marchant/32/32828_2.png) [@Pablo\_Marchant](https://discourse.julialang.org/u/Pablo_Marchant)\
**Post date:** [May 1, 2022, 5:45pm UTC](https://discourse.julialang.org/t/plot-ticks-at-both-top-and-bottom-axis/9550/7 "2022-05-01T17:45:31Z")

</div>

This is an old post but something I stumbled with today and took me a bit to find a fix. Copying here something I put on an associated issue in Plots.jl github page ([https://github.com/JuliaPlots/Plots.jl/issues/2218](https://github.com/JuliaPlots/Plots.jl/issues/2218)), just in case it can help someone.

Not a proper fix, but here is a workaround I found. I just create a twin axis in each direction, match the x and y boundaries and remove labels using a copy\_ticks function.

```julia
function twiny(sp::Plots.Subplot)
    sp[:top_margin] = max(sp[:top_margin], 30Plots.px)
    plot!(sp.plt, inset = (sp[:subplot_index], bbox(0,0,1,1)))
    twinsp = sp.plt.subplots[end]
    twinsp[:xaxis][:mirror] = true
    twinsp[:background_color_inside] = RGBA{Float64}(0,0,0,0)
    Plots.link_axes!(sp[:yaxis], twinsp[:yaxis])
    twinsp
end
twiny(plt::Plots.Plot = current()) = twiny(plt[1])

function copy_ticks(sp::Plots.Subplot)
    ptx = twinx(sp)
    plot!(ptx,xlims=xlims(plt),ylims=ylims(plt),xformatter=_->"",yformatter=_->"")
    pty = twiny(sp)
    plot!(pty,xlims=xlims(plt),ylims=ylims(plt),xformatter=_->"",yformatter=_->"")
end
copy_ticks(plt::Plots.Plot = current()) = copy_ticks(plt[1])

plt = plot(sin)
copy_ticks()
display(plt)
savefig("sine.png")

```

This was built with code from two sources:

- code for twiny ([plotly - Julia: two x axes for plot of same data - Stack Overflow](https://stackoverflow.com/questions/64176617/julia-two-x-axes-for-plot-of-same-data))
- code to remove labels on twin axes ([Avoid repeating tick labels with subplots in Plots.jl](https://discourse.julialang.org/t/avoid-repeating-tick-labels-with-subplots-in-plots-jl/351))

![sine](https://global.discourse-cdn.com/julialang/original/3X/4/9/491ce2e7a44eb1c1d083f7eebf81daa36aa74f19.png)

---

_[View the full topic](https://discourse.julialang.org/t/plot-ticks-at-both-top-and-bottom-axis/9550)._
