I would like to fill the area between my plot and the x-axis. I tried also the fillbetween library but I cannot figure out exactly how it work.



        style = thick,
        scale only axis=true,
        xmin=-1 ,
        xmax=4 ,
            fill = green,
            fill opacity=0.3] {x^2 - 2*x + 2};


enter image description here

  • If you want to use pgf-plot instead of plain TikZ, you can also follow one of the numerous questions about how to fill under a curve.
    – SebGlav
    Mar 8, 2021 at 17:44

1 Answer 1


enter image description hereSomething like this?


    \draw[very thin, gray!30, step=1 cm](-4.9,-3.9) grid (4.9,3.9);

    \fill [green!30, domain=0:2, variable=\x]
      (0, 0)
      -- plot ({\x}, {\x*\x-2*\x+2})
      -- (2, 0)
      -- cycle;

    \draw [thick] [->] (-5,0)--(5,0) node[right, below] {$x$};
     \foreach \x in {-4,...,4}
       \draw[xshift=\x cm, thick] (0pt,-1pt)--(0pt,1pt) node[below] {$\x$};

    \draw [thick] [->] (0,-4)--(0,4) node[above, left] {$y$};
     \foreach \y in {-3,...,3}
       \draw[yshift=\y cm, thick] (-1pt,0pt)--(1pt,0pt) node[left] {$\y$};

    \draw [domain=0:2, variable=\x]
      plot ({\x}, {\x*\x-2*\x+2}) node[right] at (2,2) {$f(x)=(x+1)^2+1$};

  • Hello Nick, thank you for your answer. How should I change your solution if, instead of a function, I have a data set from table?
    – Fly
    Mar 8, 2021 at 17:27
  • unfortunately, I have not really done anything with data sets with LaTeX. I wish I could be of more help.
    – Nick B
    Mar 8, 2021 at 18:05

Not the answer you're looking for? Browse other questions tagged .