# Twinx shows left yticks on right y axis

**URL:** https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372
**Category:** Visualization
**Tags:** plotting, plots
**Created:** [March 17, 2021, 11:12am UTC](https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372 "2021-03-17T11:12:22Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)
#### Post date: [March 17, 2021, 11:12am UTC](https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372/1 "2021-03-17T11:12:22Z")

</div>

I am struggling to generate a plot with two y-axes. The left y-ticks show up on the right y-axis. Also, I am uisng ` rightmargin = 1.5Plots.cm, box = :on` because the label margins are [broken](https://github.com/JuliaPlots/Plots.jl/issues/3210).

```julia
using Plots

pyplot()

plot(rand(10), leg=false, ylims=(-.1,1), framestyle=:box, rightmargin = 1.5Plots.cm, box = :on)

plot!(twinx(), leg=false, 100*rand(10), ylims=(0,100), ylabel="right")

```

Using the GR backend works in this simple example, but it breaks in my code. Are there any other ways to fix the axis? Is this a bug that should be reported?

---

<div class="post-metadata">

### Author: ![Woodmouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/woodmouth/32/24394_2.png) [@Woodmouth](https://discourse.julialang.org/u/Woodmouth)
#### Post date: [April 27, 2023, 10:46am UTC](https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372/2 "2023-04-27T10:46:27Z")

</div>

I have the same issue. Still no solution?

---

<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: [April 27, 2023, 12:33pm UTC](https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372/3 "2023-04-27T12:33:38Z")

</div>

Your code seems to work fine for me, Win11, Julia 1.8.5, PyPlot v2.11.1, Plots v1.38.10:

 ![Plots_pyplot_twinx_2_y_axes](https://global.discourse-cdn.com/julialang/original/3X/b/2/b20dff5828b3150de904c79c375e9028cb127211.png)

---

<div class="post-metadata">

### Author: ![Christopher\_Fisher](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher_fisher/32/26132_2.png) [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)
#### Post date: [April 27, 2023, 7:05pm UTC](https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372/4 "2023-04-27T19:05:48Z")

</div>

It also works for me now.

**Version Info**

Julia 1.9.0 RC2  
Ubuntu 20.04

[91a5bcdd] Plots v1.38.10  
[d330b81b] PyPlot v2.11.1

@Woodmouth, what is your version information? I am wondering if you need to upgrade your packages.

---

<div class="post-metadata">

### Author: ![Woodmouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/woodmouth/32/24394_2.png) [@Woodmouth](https://discourse.julialang.org/u/Woodmouth)
#### Post date: [April 28, 2023, 10:50am UTC](https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372/5 "2023-04-28T10:50:56Z")

</div>

Updating the packages worked. Thanks! 🙂

---

<div class="post-metadata">

### Author: ![Woodmouth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/woodmouth/32/24394_2.png) [@Woodmouth](https://discourse.julialang.org/u/Woodmouth)
#### Post date: [April 28, 2023, 11:18am UTC](https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372/6 "2023-04-28T11:18:10Z")

</div>

Never mind, it was not the package versions but rather that I had set `default(framestyle=:box)` which meant that the framestyle of the twinx plot was also set to `:box` which apparently breaks it.

A separate issue is that even though the twinx axis does work now, we do loose the line at the top, so it seems as though twinx perhaps overwrites the framestyle somehow, even though that probably shouldn’t be the intended behavior. I would prefer to to have the line at the top of the plot like it should if the framestyle was set to `box`.

```julia
using Plots
Plots.reset_defaults()
pyplot()

#default(framestyle=:box)

plot(rand(10), leg=false, ylims=(-.1,1), rightmargin = 1.5Plots.cm, box = :on)

plot!(twinx(), leg=false, 100*rand(10), framestyle=:box, ylims=(0,100), ylabel="right")

```

---

<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: [April 28, 2023, 11:44am UTC](https://discourse.julialang.org/t/twinx-shows-left-yticks-on-right-y-axis/57372/7 "2023-04-28T11:44:24Z")

</div>

> [@Woodmouth](#):
>
> I would prefer to to have the line at the top of the plot like it should if the framestyle was set to `box`.

Just hammer a last nail in the coffin:

```julia
plot!(framestyle=:box)

```
