I use this for draw tangents to an arbitrary plot. For example:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usetikzlibrary{intersections}
\makeatletter
\def\parsenode[#1]#2\pgf@nil{%
\tikzset{label node/.style={#1}}
\def\nodetext{#2}
}
\tikzset{
add node at x/.style 2 args={
name path global=plot line,
/pgfplots/execute at end plot visualization/.append={
\begingroup
\@ifnextchar[{\parsenode}{\parsenode[]}#2\pgf@nil
\path [name path global = position line #1-1]
({axis cs:#1,0}|-{rel axis cs:0,0}) --
({axis cs:#1,0}|-{rel axis cs:0,1});
\path [xshift=1pt, name path global = position line #1-2]
({axis cs:#1,0}|-{rel axis cs:0,0}) --
({axis cs:#1,0}|-{rel axis cs:0,1});
\path [
name intersections={
of={plot line and position line #1-1},
name=left intersection
},
name intersections={
of={plot line and position line #1-2},
name=right intersection
},
label node/.append style={pos=1}
] (left intersection-1) -- (right intersection-1)
node [label node]{\nodetext};
\endgroup
}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}[>=latex]
\begin{axis}[
grid,
axis x line=center,
axis y line=center,
xtick={-5,-4,...,5},
ytick={-5,-4,...,5},
xlabel={$x$},
ylabel={$y$},
xlabel style={below right},
ylabel style={above left},
xmin=-5.5,
xmax=5.5,
ymin=-5.5,
ymax=5.5,
tangent/.style={
add node at x={2}{
[
sloped,
append after command={(\tikzlastnode.west) edge [thick,black] (\tikzlastnode.east)},
minimum width=0.2\textwidth
]
}
}]
\addplot[color=black,smooth, tangent] coordinates {
(-5,-5)
(-3,-4)
(-2,-1)
(0,0)
(1,2)
(2,3)
(3,3)
(4,1)
};
\end{axis}
\end{tikzpicture}
\end{document}
The problem is that I want more tangents, not only one. For example one more at the point (-3,f(-3)). Is it possible?
I tried some solutions, but I got only errors. Maybe I don't understand Jake's code...
Thank's in advanced!!!


\addplotby\addplot[color=black,smooth, tangent/.list={2,3},domain=1:4] {(1/162)*pow(\x,5)+17/162*pow(\x,4)-43/162*pow(\x,3)-179/162*pow(\x,2)+212/81*\x+134/81};. – Jun 15 '19 at 14:18