How can I shade the region between two functions?

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.

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

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?

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)),
        ),
      )
    },
  )
})