Chris1
June 25, 2025, 10:19am
1
I would like to shade in the region between the two functions shown below
#import "@preview/cetz:0.3.4"
#import "@preview/cetz-plot:0.1.1"
#cetz.canvas({
import cetz.draw: *
import cetz-plot: *
plot.plot(
name: "a",
size: (5,5),
x-tick-step:1,
y-tick-step:1,
axis-style: "school-book",
{
plot.add(
domain: (-2,2),
x=>calc.pow(x,2),
)
plot.add(
domain: (0,2),
x=>calc.root(x,2)
)
}
)
})
We can see an area between the two functions shown between (0,0) and (1,1).
How can I shade it in?
Thank you.
Andrew
June 25, 2025, 11:46am
2
With add-fill-between
.
#import "@preview/cetz:0.4.0"
#import "@preview/cetz-plot:0.1.2"
#cetz.canvas({
import cetz.draw: *
import cetz-plot: *
plot.plot(
size: (5, 5),
x-tick-step: 1,
y-tick-step: 1,
axis-style: "school-book",
{
plot.add(domain: (-2, 2), x => calc.pow(x, 2))
plot.add(domain: (0, 2), x => calc.root(x, 2))
plot.add-fill-between(
domain: (0, 1),
x => calc.pow(x, 2),
x => calc.root(x, 2),
)
},
)
})
1 Like
Chris1
June 26, 2025, 4:00am
3
Thanks very much.
That’s got it.
I had a read of the manual and figured out how to change the colour of the fill.
To add on another question without starting a new post, is there a way I can change the pattern of the fill as well as the colour. Maybe to some lines or a criss-cross pattern?
Andrew
June 26, 2025, 3:03pm
4
Use tiling
?
#import "@preview/cetz:0.4.0"
#import "@preview/cetz-plot:0.1.2"
#cetz.canvas({
import cetz.draw: *
import cetz-plot: *
plot.plot(
size: (5, 5),
x-tick-step: 1,
y-tick-step: 1,
axis-style: "school-book",
{
plot.add(domain: (-2, 2), x => calc.pow(x, 2))
plot.add(domain: (0, 2), x => calc.root(x, 2))
plot.add-fill-between(
domain: (0, 1),
x => calc.pow(x, 2),
x => calc.root(x, 2),
style: (
stroke: none,
fill: tiling(size: (3pt, 3pt), square(stroke: gray)),
),
)
},
)
})