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

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-create-a-snippet-small-plot-inside-a-plot-with-plots/91838>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 19, 2022, 8:50am UTC](https://discourse.julialang.org/t/is-it-possible-to-create-a-snippet-small-plot-inside-a-plot-with-plots/91838 "2022-12-19T08:50:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 19, 2022, 8:50am UTC](https://discourse.julialang.org/t/is-it-possible-to-create-a-snippet-small-plot-inside-a-plot-with-plots/91838/1 "2022-12-19T08:50:04Z")

</div>

Hi all,

I want to create a plot like this:  
 ![Capture d’écran_2022-12-19_15-47-12](https://global.discourse-cdn.com/julialang/original/3X/9/d/9dbb74a057bd5d0988a52644aea31b2f706869e9.png)

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:

```julia
using Plots, LaTeXStrings, ValidatedNumerics
gr()

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]
end

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)
end

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))])

```

---

<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:** [December 19, 2022, 10:50pm UTC](https://discourse.julialang.org/t/is-it-possible-to-create-a-snippet-small-plot-inside-a-plot-with-plots/91838/2 "2022-12-19T22:50:31Z")

</div>

You can use insets, see for instance [this post](https://discourse.julialang.org/t/how-to-add-an-inset-to-a-plot/37189/4).
