WeBWorK Main Forum

TikZ addplot with "name path"

TikZ addplot with "name path"

by Andras Balogh -
Number of replies: 2

I am not sure why naming a plot in a tdoes not seem to work for me.

This works without using name in the addplot line:

$graph_imageb = createTikZImage();
$graph_imageb->texPackages(["pgfplots"]);
$graph_imageb->BEGIN_TIKZ
\begin{axis}[
           xmin=-3, xmax=3,
           ymin=-10, ymax=10,
           xtick distance=1, ytick distance=4 ]
\addplot[blue, ultra thick] (x,5*x*x-2*x);
\end{axis}
END_TIKZ

But changing the addplot line to include name does not: \addplot[name path=F, blue, ultra thick] (x,5*x*x-2*x);

Ultimately I wish to use the names to fill in between two graphs.

In reply to Andras Balogh

Re: TikZ addplot with "name path"

by Glenn Rice -

You need to load the pgfplots fillbetween library to use the "name path" key.

For example:

$graph_imageb = createTikZImage();
$graph_imageb->texPackages(["pgfplots"]);
$graph_imageb->addToPreamble('\usepgfplotslibrary{fillbetween}');
$graph_imageb->BEGIN_TIKZ
\begin{axis}[
    xmin=-3, xmax=3,
    ymin=-10, ymax=10,
    xtick distance=1, ytick distance=4 ]
    \addplot[blue,ultra thick,name path=f] (x,5*x^2-2*x);
    \addplot[blue,ultra thick,name path=g] (x,-5*x*x+2*x+3);
    \addplot [gray!50] fill between [
        of=f and g,
        soft clip={domain=-1:1},
    ];
\end{axis}
END_TIKZ

In reply to Glenn Rice

Re: TikZ addplot with "name path"

by Andras Balogh -

Thanks!

I new about fillbetween but i thought it will be needed only for the actual fill part, and wanted to do things step-by-step. :-(