# Inset plot with twin axis

**URL:** <https://discourse.julialang.org/t/inset-plot-with-twin-axis/98038>\
**Category:** New to Julia\
**Tags:** plotting, plots\
**Created:** [April 28, 2023, 12:04pm UTC](https://discourse.julialang.org/t/inset-plot-with-twin-axis/98038 "2023-04-28T12:04:36Z")\
**Posts on this page:** 6\
**Page:** 1

<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, 12:04pm UTC](https://discourse.julialang.org/t/inset-plot-with-twin-axis/98038/1 "2023-04-28T12:04:36Z")

</div>

I want a plot with an inset that has two y axes. Even when I first make a plot with a twin axis, and then try to add it as an inset, it modifies the plot that the inset should be in.

```julia
using Plots
pyplot()

twinPlot = plot(rand(10))
plot!(twinx(), 10rand(10))

mainPlot = plot(100rand(10))
plot!(twinPlot,
    inset = bbox(0, 0, 0.4, 0.4, :center),
    subplot = 2)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/f/9/f917d02c8edfe08d3a9405830b48ace336c17f54.png)

This thread ([How to add an inset to a plot - #13 by SDA](https://discourse.julialang.org/t/how-to-add-an-inset-to-a-plot/37189/13)) mentions a recipe to do something similar, but they link to something that seems to be missing now: [https://docs.juliaplots.org/latest/generated/gr/#gr-ref40](https://docs.juliaplots.org/latest/generated/gr/#gr-ref40)

Thanks for any suggestions!

---

<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, 12:40pm UTC](https://discourse.julialang.org/t/inset-plot-with-twin-axis/98038/2 "2023-04-28T12:40:18Z")

</div>

Would you like to insert an inset with dual axes as follows?

 ![Plots_gr_inset_dual_axes](https://global.discourse-cdn.com/julialang/original/3X/5/3/5365536ef99a55b0772abc7d2b76b6dc54916ea6.png)

> **Plots.jl code**
>
> ```julia
> using Plots; gr(dpi=600)
> 
> p = plot(100rand(10), c=:green)
> plot!(p, rand(10), c=:blue, inset=bbox(0, 0, 0.4, 0.4, :center), subplot=2)
> plot!(twinx(p[2]), 10rand(10), c=:red)
> plot!(p[2], framestyle=:box)
> 
> ```

---

<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, 1:31pm UTC](https://discourse.julialang.org/t/inset-plot-with-twin-axis/98038/3 "2023-04-28T13:31:37Z")

</div>

Yes, that looks great! Could you share the code?

---

<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, 1:39pm UTC](https://discourse.julialang.org/t/inset-plot-with-twin-axis/98038/4 "2023-04-28T13:39:05Z")

</div>

As requested, the code is now included below the plot.

---

<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, 2:10pm UTC](https://discourse.julialang.org/t/inset-plot-with-twin-axis/98038/5 "2023-04-28T14:10:19Z")

</div>

Thank you very much! For some reason I can’t seem to make the framestyle of the outer plot be boxed with ticks on all sides. Is that something you might also be able to help me with?

---

<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, 2:52pm UTC](https://discourse.julialang.org/t/inset-plot-with-twin-axis/98038/6 "2023-04-28T14:52:09Z")

</div>

> [@Woodmouth](#):
>
> I can’t seem to make the framestyle of the outer plot be boxed with ticks on all sides

From the Plots.jl call center, the `pgfplotsx()` and `pyplot()` backends provide this feature, but I don’t know of an easy solution for the others without labour.  
Please check the following page [here](https://github.com/JuliaPlots/Plots.jl/issues/2218).
