Is it Possible to Create a Snippet / small plot inside a plot with Plots?

Hi all,

I want to create a plot like this:
Capture d’écran_2022-12-19_15-47-12

I have the code to create the big plot (the circumscribed polygon), is it possible to crop a part and put it at designated area, like putting a legend on topleft? Then put the annotations afterwards. Is there any other suggestion for this?

this is the code for the big plot:

using Plots, LaTeXStrings, ValidatedNumerics

f(x) = x^2

#plot(f, 0, 2, aspect_ratio=:equal, fill=(0, :green), alpha=0.2, label="")

function make_intervals(N=10)
    xs = range(0, stop=2, length=N+1)
    return [xs[i]..xs[i+1] for i in 1:length(xs)-1]

intervals = make_intervals()

# Plot Riemann Sums
intervals = make_intervals(6)
p = plot()
for X in intervals
    Y = f(X)

    plot!(IntervalBox(X, Interval(0, Y.hi)), c=:blue, label="", alpha=0.1)

plot!(f, 0, 2, xtick=false, xlims=(0,2),
	legend=:topleft, label=L"x^2")

annotate!([(1.2,0.85, (L"R_{n}", 11, :black))])
annotate!([(0.2,-0.07, (L"x_{0}", 6, :black))])
annotate!([(0.5,-0.07, (L"x_{1}", 6, :black))])
annotate!([(0.85,-0.07, (L"x_{2}", 6, :black))])
annotate!([(0.95,0.27, (L"f(x_{2})", 6, :black))])
annotate!([(1.2,-0.07, (L"\dots", 6, :black))])
annotate!([(1.5,-0.07, (L"x_{n-1}", 6, :black))])
annotate!([(1.6,1, (L"f(x_{n-1})", 6, :black))])
annotate!([(1.85,-0.07, (L"x_{n}", 6, :black))])
annotate!([(1.95,1.37, (L"f(x_{n})", 6, :black))])

You can use insets, see for instance this post.

1 Like