Menu

#228 \draw has problems with declared functions

v1.0 (example)
open
nobody
5
2019-11-13
2019-11-13
Consti P
No

I have declared my function because I need to calculate several points:

\begin{tikzpicture}[
declare function={
func(\x)=(\x-2)^3-0.4*(\x)^2+2;
}
]

Now I have full access and can plot it with \addplot {func(x)}; (or something similar).

The problem comes when trying to use \draw with points calculated from it.
Take for example \draw (axis cs:0,func(0)) -- (axis cs:2,func(2));. This should create a line between the points on the function. Instead, nothing gets drawn. The startpoint is correctly evaluated (try to add [->]), but the endpoint remains the same. Even if I set the endpoint to a fixed one, the result is the same.
There is another problem however. If I try \draw (axis cs:0,0) -- (axis cs:2,func(2)); it looks correct, if I try to add a node at the end however, that node gets drawn somewhere (seems to be center-top outside of the domain).

Currently the solution is to declare both points with \coordinate (p) at (axis cs:0,func(0)); and then draw a line between these. This seems to work fine.

Discussion