# Magnifier lens of various shapes in Plots or Makie

I came across the two gif animations in the following slides in a talk that I attended last year (they are not moving in the pictures that I attached).

I wonder if I can reproduce the same animations, in particular, the circular / elliptical magnifier lens with Plots or Makie.

2 Likes

In Plots I would use `lens` with borders turned off and draw an ellipse on top with `Shape`. You may even manage to draw the ellipse in the original plot and have it zoom with the lens. This won’t be perfect, but it might work.

I found `lens` in the documentation of `Plots`. I will try to tweak around with the provided example tomorrow. At the moment it seems that any attributes I pass to `inset` will also apply to the main plot.
https://docs.juliaplots.org/latest/generated/gr/#gr-ref40

Drawing ellipse and lines is not too difficult, the main problem is probably to be to turn off the right things.

Here is a working example

``````using Plots, LinearAlgebra

circle1 = 0.5.+0.1.*cis.(0:0.01:2pi)
circle2 = 2.0+2.0im.+cis.(0:0.01:2pi)

id(z) = norm(z-0.5) <=0.1
ani = @animate for n = 2:10:400
E = randn(n,n)/sqrt(n)|>eigvals
E|>x->scatter(x,xlims=(-2,3),ylims=(-2,3),ratio=1,leg=false,ms=2)
(10*(E[id.(E)].-(0.5+0im)).+(2+2.0im))|>scatter!
plot!(circle1,fill=true,alpha=0.3,c=:green)
plot!(circle1,lw=2,c=:orange)
plot!(circle2,fill=true,alpha=0.1,c=:green)
plot!(circle2,lw=2,c=:orange)
plot!([0.5,1],[0.1,2],c=:orange,lw=2)
plot!([0.6,2],[0,1],c=:orange,lw=2)
title!("Local Circular Law")
end
gif(ani,"ani.gif")
`````` 7 Likes