# How to Fill Area between y-axis and the curve $x^{2}$ correctly?

**URL:** <https://discourse.julialang.org/t/how-to-fill-area-between-y-axis-and-the-curve-x-2-correctly/91417>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [December 8, 2022, 9:17am UTC](https://discourse.julialang.org/t/how-to-fill-area-between-y-axis-and-the-curve-x-2-correctly/91417 "2022-12-08T09:17:21Z")\
**Posts on this page:** 3\
**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 8, 2022, 9:17am UTC](https://discourse.julialang.org/t/how-to-fill-area-between-y-axis-and-the-curve-x-2-correctly/91417/1 "2022-12-08T09:17:21Z")

</div>

Hi all,

I want to recreate this plot.  
 ![Capture d’écran_2022-12-08_16-16-13](https://global.discourse-cdn.com/julialang/original/3X/f/5/f5c30e2f548a577d934ef115bcc37b455a641855.png)

My code currently create this far away from the desired plot:

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = x^(2)

plot(f, ylims= (0,33), xlims=(-2,10), framestyle=:zerolines,
	legend=:outerright, bottom_margin=5mm, 
	label=L"f(x) = x^{2}", 
	size=(720, 360), tickfontsize=10)

plot!(f,3,5, label=L"B_{n}", fill=(0, 0.45, :green))
plot!(f, 0,4.5, 
	fillrange = 20, fillalpha = 0.35, c = 1, 
	label = L"A_{n}")

```

 ![Capture d’écran_2022-12-08_16-16-57](https://global.discourse-cdn.com/julialang/original/3X/0/2/0233b75aaef13685c965c9dea76f8a8581ce9025.png)

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [December 8, 2022, 9:34am UTC](https://discourse.julialang.org/t/how-to-fill-area-between-y-axis-and-the-curve-x-2-correctly/91417/2 "2022-12-08T09:34:19Z")

</div>

The tricky part is this:

```julia
using Plots, LaTeXStrings, Plots.PlotMeasures
gr()

f(x) = x^(2)

plot(f, ylims= (0,33), xlims=(-2,10), framestyle=:zerolines,
	legend=:outerright, bottom_margin=5mm, 
	label=L"f(x) = x^{2}", 
	size=(720, 360), tickfontsize=10)

plot!(f,3,5, label=L"B_{n}", fill=(0, 0.45, :green))
plot!(f, 3,5, 
	fillrange = f(5), fillalpha = 0.35, c = 1, 
	label = L"A_{n}")
plot!([0, 3], [f(3), f(3)], fillalpha = 0.35, c = 1, label = "", linewidth = 0, fillrange = f(5))

```

---

<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 8, 2022, 11:27am UTC](https://discourse.julialang.org/t/how-to-fill-area-between-y-axis-and-the-curve-x-2-correctly/91417/3 "2022-12-08T11:27:47Z")

</div>

> [@BeastyBlacksmith](#):
>
> ```julia
> using Plots, LaTeXStrings, Plots.PlotMeasures
> gr()
> 
> f(x) = 
> 
> ```

Thanks @BeastyBlacksmith you are the best! So the last line is to fill a rectangle, that shall do the tricks.
