# Control Plots draw order with multiple y-axes

**URL:** <https://discourse.julialang.org/t/control-plots-draw-order-with-multiple-y-axes/115223>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [June 5, 2024, 11:16am UTC](https://discourse.julialang.org/t/control-plots-draw-order-with-multiple-y-axes/115223 "2024-06-05T11:16:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [June 5, 2024, 11:16am UTC](https://discourse.julialang.org/t/control-plots-draw-order-with-multiple-y-axes/115223/1 "2024-06-05T11:16:26Z")

</div>

I’m trying to make a line plot vs the right y-axis and a bar plot on the left y-axis using `twinx` and I run into the problem that the bars obscure the line plot.

Is there any way to make Plots draw the line plot on top of the bars in this case while still keeping the line plot y-axis to the right?

```julia
let
       plt = plot(randn(10), ylabel="line plot")
       bar!(twinx(plt), fill(20, 10), color=:orange, label=false, ylabel="bar plot")
end

```

![image](https://global.discourse-cdn.com/julialang/original/3X/8/4/841928feee0d89e6281d65a5f542ad36b91ca249.png)

I can to some extent work around this by reducing the alpha value of the bars, but since I need to plot multiple bar series (using StatsPlots.groupedbar) I’d like to avoid this.

---

<div class="post-metadata">

**Author:** ![DrChainsaw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drchainsaw/32/8497_2.png) [@DrChainsaw](https://discourse.julialang.org/u/DrChainsaw)\
**Post date:** [June 5, 2024, 11:40am UTC](https://discourse.julialang.org/t/control-plots-draw-order-with-multiple-y-axes/115223/2 "2024-06-05T11:40:31Z")

</div>

Found one (probably unofficial) way to do it based on the source code of `Plots.twin`:

```julia
let
       plt = bar(fill(20, 10), color=:orange, label=false, ylabel="bar plot")
       plot!(twinx(plt), randn(10), ylabel="line plot")
       plt[1][:yaxis][:mirror] = true
       plt[2][:yaxis][:mirror] = false
       plt
end

```
