# How to Fill Horizontal Slicing under a Curve?

**URL:** <https://discourse.julialang.org/t/how-to-fill-horizontal-slicing-under-a-curve/92218>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [December 28, 2022, 9:47am UTC](https://discourse.julialang.org/t/how-to-fill-horizontal-slicing-under-a-curve/92218 "2022-12-28T09:47:21Z")\
**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 28, 2022, 9:47am UTC](https://discourse.julialang.org/t/how-to-fill-horizontal-slicing-under-a-curve/92218/1 "2022-12-28T09:47:21Z")

</div>

Hi all,

this is only a simple fix needed, I want to fill an area like this image:  
 ![Capture d’écran_2022-12-28_16-44-50](https://global.discourse-cdn.com/julialang/original/3X/9/8/9897b257dad0341b95736c3204ccc52ff4c553c6.png)

I try but it created a square fill, I want the horizontal slicing to follow the shape of the curve. Can it be done?

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

# For the curve
f(x) = x^3

plt = plot(;xtick=0:1:2, xlims=(-2,2), ylims = (0, 5), 
	 legend = :topright, framestyle=:zerolines, label = "", bottom_margin=10mm)
a= π/2

# Plotting time
plot(plt, f, 0, a, label="")

# First filling
plot!(f, 0,2.5, 
	fillrange = 20, fillalpha = 0.25, c = 1, 
	label = "")

# Second filing
plot!([0,f(1)], [1.5, 1.5], 
	fillrange = 1, fillalpha = 0.35, c = 1, 
	label = "", linewidth = 0)

```

---

<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 29, 2022, 7:12am UTC](https://discourse.julialang.org/t/how-to-fill-horizontal-slicing-under-a-curve/92218/2 "2022-12-29T07:12:41Z")

</div>

Yes, I managed to make it manually,

but it would be better if there is a function or a method so I can fill horizontal slicing easily for any kind of graphs.

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

# For the curve
f(x) = x^3

plt = plot(;xtick=0:1:2, xlims=(-2,2), ylims = (0, 5), 
	 legend = :topright, framestyle=:zerolines, label = "", bottom_margin=10mm)
a= π/2

# Plotting time

plot(f, ylims= (0,13), xlims=(0,6), 
	ytick=true, xtick=true, framestyle=:zerolines,
	legend=:topright, bottom_margin=5mm, 
	label=L"f(x) = x^{3}", 
	size=(720, 360), tickfontsize=10)

# First filling
plot!(f, 0,4.5, 
	fillrange = 20, fillalpha = 0.35, c = 1, 
	label = "")

# Second filling
# Fill from x=1.1 to x=1.4 with lower bound will be f and the height is fillrange
plot!(f,1.1,1.4, 
	fillrange = 2.8, fillalpha = 0.65, c = 1, 
	label = L"\sqrt[3]{y}")

# Fill from (0,f(1.1) to (1.1,f(1.1))
# with the height is fillrange
plot!([0,1.1], [f(1.1), f(1.1)], 
	fillrange = f(1.41), fillalpha = 0.65, c = 1, 
	label = "", linewidth = 0)

annotate!([(1.5,2.3, (L"△y", 10, :black))])

```
