# Using lens in Plots.jl with subplots

**URL:** <https://discourse.julialang.org/t/using-lens-in-plots-jl-with-subplots/117162>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [July 17, 2024, 8:17pm UTC](https://discourse.julialang.org/t/using-lens-in-plots-jl-with-subplots/117162 "2024-07-17T20:17:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pex/32/49986_2.png) [@PeX](https://discourse.julialang.org/u/PeX)\
**Post date:** [July 17, 2024, 8:17pm UTC](https://discourse.julialang.org/t/using-lens-in-plots-jl-with-subplots/117162/1 "2024-07-17T20:17:12Z")

</div>

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:

```julia
#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!

---

<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:** [July 18, 2024, 11:23am UTC](https://discourse.julialang.org/t/using-lens-in-plots-jl-with-subplots/117162/3 "2024-07-18T11:23:20Z")

</div>

I think this example should be self-explanatory:

```julia
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)

```

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