add tag
JeT
**Question**

I need to automate calculations.

Strangely, declaring function by `\pgfmathdeclarefunction{PnL}` does not allow me to use the calculations when I call `Pnl{3.5}` and get the `y` coordinate.

Details in the code.

![TAGammaQuestion.png](/image?hash=4a19ce58f7f5a8b252088c61f05cdc9089547de50c82d4d3f744d57ec529fce0)

**Next step**

Of course animation :) The dashed curve will move along the y axis from its orinal position (dashed) to south, displaying more and more of the gray area.

```
\documentclass[border =2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{
	calc,
	intersections,
	positioning,
}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\usepgfplotslibrary{
	fillbetween,
}

\begin{document}

\newcommand*{\ShowIntersection}{
\fill 
    [name intersections={of=PnL and line, name=i, total=\t}] 
    [red, opacity=1, every node/.style={above left, black, opacity=1}] 
    \foreach \s in {1,...,\t}{(i-\s) circle (3pt)
        node [above] {}};
}

\begin{tikzpicture}
\pgfmathdeclarefunction{PnL}{0}{\pgfmathparse{0.5*(x^2)-2}}


\begin{axis}[%customaxis2,
   axis lines=middle,
   xtick={\empty},
   ytick={\empty},
   ytick       = {0},
   ticklabel style={font=\scriptsize},
   xlabel=$dS$,
   ylabel=$d\Pi$,
   xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
   ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west},
    samples     = 51,
%    domain      = -3:3,
%    xmin = -2, xmax = 5,
%    ymin = -5, ymax = 10,
  ]

% X axis
  \addplot[name path=line, gray, samples=2,no markers, line width=1pt] {0};
% curve
  \addplot[purple,dashed,samples=51,smooth,thick, mark=none, ] {PnL+2};
% dashed curve, inital position
  \addplot[purple,samples=51,smooth,name path=PnL, thick, mark=none, ] {PnL};

%filled area
  \addplot fill between[ 
    of = PnL and line, 
    split, % calculate segments
    every even segment/.style = {white}, %Only trick I found to avoi
    every odd segment/.style  = {gray!60}
  ] {};

% red intersection points to X axis
 \ShowIntersection  

% cord but too manual
  \coordinate (P) at (-3.5, 3.8);
%  \coordinate (P) at (-3.5, \Pnl(-3.5)  );
  \coordinate (Q) at (3.5, 3.8);

% too manual
\node[pin=130:$\Gamma$,draw=black,circle] at (-3.5, 3.8) {};
%\node[pin=130:$\Gamma$,draw=black,circle] at (-3.5, \Pnl(-3.5)) {};
\node[pin=40:$\Gamma$,draw=black,circle] at (3.5, 3.8) {};

% too manual
  \draw [latex-latex,dashed, thick, name path global=HorizontalLine] (P) -- (Q) node[above] {};

% too manual, but did not manage to place it in the center of the filled area
   \draw (0,-0.8) node {$\Theta^{-}$};	

\end{axis}
\end{tikzpicture}
\end{document}
```

**Note**
The orginal graph
![Gammatheta.png](/image?hash=f50c7fc0d593143b57cdb199b1a05e3794152a5e99772690a4021fb6956e9c5c)
Top Answer
user 3.14159
When declaring a function, you may want to specify and use the variables. In your case this may mean something like
```
\pgfmathdeclarefunction{PnL}{1}{\pgfmathparse{0.5*(#1*#1)-2}}
```
where `{1}` says that this is a function of one variable, and `#1` represents this argument. Note that I use `#1*#1` instead of `#1^2` since pgf has somewhat strange conventions concerning the sign. An arguably more user-friendly way to declare the  function is to use the key
```
declare function={PnL(\x)=0.5*\x*\x-2;},
```
instead. I made a few more unrelated changes.

```
\documentclass[border =2mm]{standalone}
\usepackage{amsmath}
\newcommand{\diff}{\mathop{}\!\mathrm{d}}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\usepgfplotslibrary{fillbetween}

\begin{document}

\newcommand*{\ShowIntersection}{
\fill 
    [name intersections={of=PnL and line, name=i, total=\t}] 
    [red, opacity=1] 
    foreach \s in {1,...,\t}{(i-\s) circle [radius=3pt]};
}

\begin{tikzpicture}
% \pgfmathdeclarefunction{PnL}{1}{\pgfmathparse{0.5*(#1*#1)-2}}
\begin{axis}[%customaxis2,
   declare function={PnL(\x)=0.5*\x*\x-2;},
   axis lines=middle,
   xtick={\empty},
   ytick={\empty},
   ytick       = {0},
   ticklabel style={font=\scriptsize},
   xlabel=$\diff S$,
   ylabel=$\diff\Pi$,
   xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
   ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west},
    samples     = 51,
%    domain      = -3:3,
%    xmin = -2, xmax = 5,
    ymin ={PnL(0)-0.1}, ymax = 10,
  ]

% X axis
  \addplot[name path=line, gray, samples=2,no markers, line width=1pt] {0};
% curve
  \addplot[purple,dashed,samples=51,smooth,thick, mark=none] {PnL(x)+2};
% dashed curve, inital position
  \addplot[purple,samples=51,smooth,name path=PnL, thick, mark=none] {PnL(x)};
  %
%filled area
  \addplot fill between[ 
    of =PnL and line, 
    split, % calculate segments
    every even segment/.style = {opacity=0}, %Only trick I found to avoi
    every odd segment/.style  = {gray!60}
  ] {};

% red intersection points to X axis
 \ShowIntersection  
 %
 \draw[latex-latex,dashed, thick, name path global=HorizontalLine,
 	nodes={solid,draw=black,circle},every pin edge/.style={solid,thin,gray,-}]
  (-3.5,{PnL(-3.5))}) node[pin=130:$\Gamma$]{}
  --
  (3.5,{PnL(3.5))}) node[pin=40:$\Gamma$]{};
 %
 \draw (0,-0.8) node {$\Theta^{-}$};	
\end{axis}
\end{tikzpicture}
\end{document}
```
![Screen Shot 2020-11-21 at 12.25.27 PM.png](/image?hash=f701e1facce989074df259aa9bf4651d43ae7e296077a6de2590335e23f14baf)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.