# Twinx() not keeping ticks in same position

**URL:** https://discourse.julialang.org/t/twinx-not-keeping-ticks-in-same-position/89623
**Category:** New to Julia
**Tags:** plots
**Created:** [November 1, 2022, 4:52pm UTC](https://discourse.julialang.org/t/twinx-not-keeping-ticks-in-same-position/89623 "2022-11-01T16:52:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![PeeVee](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@PeeVee](https://discourse.julialang.org/u/PeeVee)
#### Post date: [November 1, 2022, 4:52pm UTC](https://discourse.julialang.org/t/twinx-not-keeping-ticks-in-same-position/89623/1 "2022-11-01T16:52:00Z")

</div>

Hi,

I’ve been trying to get a shared x-axis to work, but it seems like twinx() is not able to keep the x-ticks in the same position.

Here is an example:

```julia
using Random, Plots

Random.seed!(2018)
plot(randn(100), ylabel="y",label="y1111111111111", leg=:outertopright)
plot!(twinx(), randn(100)*10,
    c=:red,
    ylabel="y2",
    leg=:outerbottomright,
    size=(600, 400))

```

![example](https://global.discourse-cdn.com/julialang/original/3X/b/e/be7cc0437fc0b2f26529f7242821fcd7347691fd.png)

Sorry if I’m missing something obvious here.

Thanks for the help.

---

<div class="post-metadata">

### Author: ![t-bltg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/t-bltg/32/25526_2.png) [@t-bltg](https://discourse.julialang.org/u/t-bltg)
#### Post date: [November 1, 2022, 5:04pm UTC](https://discourse.julialang.org/t/twinx-not-keeping-ticks-in-same-position/89623/2 "2022-11-01T17:04:01Z")

</div>

Probably [[BUG] legend=:outertopleft misalgins x-axes of twinx · Issue #2894 · JuliaPlots/Plots.jl · GitHub](https://github.com/JuliaPlots/Plots.jl/issues/2894).

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 1, 2022, 6:58pm UTC](https://discourse.julialang.org/t/twinx-not-keeping-ticks-in-same-position/89623/3 "2022-11-01T18:58:17Z")

</div>

Note that there is a workaround this bug, using layouts, if needed.
