Background Color in inset plots in Plots.jl

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:

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! :slight_smile:

Hi and welcome.

You can use the Plots.jl subplot attribute bg_subplot (see list here):

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.

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:

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!