# Background Color in inset plots in Plots.jl

**URL:** https://discourse.julialang.org/t/background-color-in-inset-plots-in-plots-jl/126717
**Category:** General Usage
**Tags:** plots, subplots
**Created:** [March 8, 2025, 7:44pm UTC](https://discourse.julialang.org/t/background-color-in-inset-plots-in-plots-jl/126717 "2025-03-08T19:44:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nidish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nidish/32/218326_2.png) [@Nidish](https://discourse.julialang.org/u/Nidish)
#### Post date: [March 8, 2025, 7:44pm UTC](https://discourse.julialang.org/t/background-color-in-inset-plots-in-plots-jl/126717/1 "2025-03-08T19:44:56Z")

</div>

Is it possible to insert inset plots with a background and a small rounded box around it so it’s more easily visible?  
Here’s an example where I can really use it. Here’s the non-runnable code I’m using to plot it. Just giving it to provide context on how I’m making the inset plot appear:

```julia
plt2 = plot(tpl, xt, lc=:blue, label="Slow Flow Synthesis");
plot!(plt2, tpl, solp_or[1,:], lc=:red, label="Numerical ODE Solution");
xlabel!(plt2, "Time (s)");
ylabel!(plt2, "Displacement (m)");
display(plt2)

plt3 = plot(plt2);
plot!(plt3, inset=bbox(.6,.5, .3,.3));
for i in 1:plt2.n
    plot!(plt3[2], plt2.series_list[i]);
end
xll = [Tmax-20, Tmax];
yll = [-1, 1]*0.4;
xlims!(plt3[2], xll...);
ylims!(plt3[2], yll...);
plot!(plt3[2], legend=false, framestyle=:box);

plot!(plt3[1], xll[[1 2 2 1 1]]', yll[[1 1 2 2 1]]', lc=:black, label=nothing);

display(plt3)

```

Any comments will be appreciated! 🙂

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/8/18187074fa5bc53e0ed8782824aa0f881bd6f987.png)

---

<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: [March 8, 2025, 8:31pm UTC](https://discourse.julialang.org/t/background-color-in-inset-plots-in-plots-jl/126717/2 "2025-03-08T20:31:12Z")

</div>

Hi and welcome.

You can use the Plots.jl subplot attribute `bg_subplot` (see [list here](https://docs.juliaplots.org/stable/generated/attributes_subplot/)):

```julia
plot!(plt3[2], plt2.series_list[i], bg_subplot=:lightyellow);

```

Changing the background color outside the subplot canvas does not seem to be possible (tbc). The example below uses a rectangular transparent gray `Shape` that had to be manually positioned before plotting the inset, which is a pain in the neck.

 ![Plots_inset_with_background_color](https://global.discourse-cdn.com/julialang/original/3X/b/3/b3ed62150130b3a239085bcd3b5bfc6d1723a62d.jpeg)

---

<div class="post-metadata">

### Author: ![Nidish](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nidish/32/218326_2.png) [@Nidish](https://discourse.julialang.org/u/Nidish)
#### Post date: [March 9, 2025, 6:14am UTC](https://discourse.julialang.org/t/background-color-in-inset-plots-in-plots-jl/126717/3 "2025-03-09T06:14:55Z")

</div>

Ah I understand. I was actually looking for the latter (background color outside the canvas).  
With some trial & error I got this, which looks quite close to what I was looking for. Here’s the additional code, in case it helps someone else:

```julia
bx0 = 360.;
by0 = -0.6;
bw = 350;
bh = 0.6;
plot!(plt3[1], Shape(bx0 .+[0,bw,bw,0], by0.+[0,0,bh,bh]), fc=:white,
      lc=:green, lw=2, opacity=.85, label=nothing);

```

Positioning the box was messy so it would be great if Julia supports something like this natively!

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