# How to draw area below a function at certain interval?

**URL:** <https://discourse.julialang.org/t/how-to-draw-area-below-a-function-at-certain-interval/83895>\
**Category:** General Usage\
**Created:** [July 7, 2022, 1:32pm UTC](https://discourse.julialang.org/t/how-to-draw-area-below-a-function-at-certain-interval/83895 "2022-07-07T13:32:35Z")\
**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:** [July 7, 2022, 1:32pm UTC](https://discourse.julialang.org/t/how-to-draw-area-below-a-function-at-certain-interval/83895/1 "2022-07-07T13:32:36Z")

</div>

Hi all,

how do we draw an area like below (definite integral)?  
 ![index](https://global.discourse-cdn.com/julialang/original/3X/4/1/41c001908f7181bbb1bc952586d67a9bd5226658.png)

and how to make the result function of the area becomes in the same box like label?

This is my code:

```julia
using Plots, LaTeXStrings
gr()

function Area(f, a, b, n)
xs = a:(b-a)/n:b
deltas = diff(xs)
cs = xs[1:end-1]
sum(f(cs[i]) * deltas[i] for i in 1:length(deltas))
end

f(x) = x^2
Area(x -> x^2, 0, 1, 50_000)

plot(f,0,1, label=L"y = x^2", legend=:outertop)
annotate!([(0.77,0.95, ("Area = ", 11, :black)),
	  (0.77,0.85, (Area(x -> x^2, 0, 1, 50_000), 11, :black))])

```

 ![Capture d’écran_2022-07-07_20-30-03](https://global.discourse-cdn.com/julialang/original/3X/7/7/7707f7f2935c94176c76cac474a704a7f4f8882c.png)

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [July 7, 2022, 3:36pm UTC](https://discourse.julialang.org/t/how-to-draw-area-below-a-function-at-certain-interval/83895/2 "2022-07-07T15:36:53Z")

</div>

Have a look at the `fill` keyword argument: [Overview · Plots](https://docs.juliaplots.org/stable/attributes/#fill)

For example:

```julia
plot(f,0,1, legend=false)
plot!(f,0.5,0.75, fill=(0, 0.25, :blue))

```

![image](https://global.discourse-cdn.com/julialang/original/3X/8/6/869c3325338721a7587fe052a5e727efeba9f4b8.png)

---

<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:** [July 8, 2022, 11:14am UTC](https://discourse.julialang.org/t/how-to-draw-area-below-a-function-at-certain-interval/83895/3 "2022-07-08T11:14:51Z")

</div>

Thanks for your help
