Using lens in Plots.jl with subplots

Hi all,
I’m trying to add zoomed insets to a figure that contains four panels. I’m not sure how to configure the lens function to be added to a specific subplot in the layout.

My plot function looks like this:

#Adjust layout for two-column figure
sp = plot(layout=(2,2))

#Plot configuration
plot(sp[1], legend=:outerright, tickfontsize=tick_font_size, guidefontsize=guide_font_size, legendfontsize=legend_font_size)
plot!(sp[1], df_plots[1].time_s, df_plots[1].eps_nm, linewidth=1)
plot!(sp[1], df_plots[2].time_s, df_plots[2].eps_nm, linewidth=1)
plot!(sp[1], df_plots[3].time_s, df_plots[3].eps_nm, linewidth=1)

plot(sp[2], legend=:outerright, tickfontsize=tick_font_size, guidefontsize=guide_font_size, legendfontsize=legend_font_size)
plot!(sp[2], df_plots[1].time_s, df_plots[1].ε_f, linewidth=1)
plot!(sp[2], df_plots[2].time_s, df_plots[2].ε_f, linewidth=1)
plot!(sp[2], df_plots[3].time_s, df_plots[3].ε_f, linewidth=1, ylimit=(-750,150))


plot(sp[3], legend=:outerright, tickfontsize=tick_font_size, guidefontsize=guide_font_size, legendfontsize=legend_font_size)
plot!(sp[3], df_plots[4].time_s, df_plots[4].eps_nm, linewidth=1)
plot!(sp[3], df_plots[5].time_s, df_plots[5].eps_nm, linewidth=1)
plot!(sp[3], df_plots[6].time_s, df_plots[6].eps_nm, linewidth=1)

plot(sp[4], legend=:outerright, tickfontsize=tick_font_size, guidefontsize=guide_font_size, legendfontsize=legend_font_size)
plot!(sp[4], df_plots[4].time_s, df_plots[4].ε_f, linewidth=1)
plot!(sp[4], df_plots[5].time_s, df_plots[5].ε_f, linewidth=1)
plot!(sp[4], df_plots[6].time_s, df_plots[6].ε_f, linewidth=1, ylimit=(-750,150))

And I want to add zoomed-in sections only to sp[2] and sp[4], and also make it without axes titles. Is this possible?

Thank you!

I think this example should be self-explanatory:

using Plots; gr(dpi=600)

x = -π:0.1:π;  y = atan.(x)

fs = 6
sp = plot(layout=(2,2), ratio=1, size=(800,600))
for i=1:4
    plot!(sp[i], x, y, legend=:outerright, tickfontsize=fs, guidefontsize=fs, legendfontsize=fs)
end
lens!([-3, -2], [-1.5, -0.5], inset=(2, bbox(0.5, 0.5, 0.3, 0.3)), tickfontsize=fs-3, ratio=1, subplot=5)
lens!([2, 3], [0.5, 1.5], inset=(4, bbox(0.1, 0.1, 0.3, 0.3)), tickfontsize=fs-3, ratio=1, subplot=6)

plot!(sp, x->0.3*sin(10x)+1, c=:blue, subplot=6)

1 Like