I want to make a tikzpicture displaying a function shifted multiple times, each time having a lighter color and line width. Using How to make Loop? and Changing color in foreach as references, I created the following code:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=1]
\begin{axis}[
axis lines=center,
grid=major,
xmin=-0.25,
xmax=10,
ymin=-0.25,
ymax=1.25,
width=15cm,
height=5cm,
]
\addplot[smooth,densely dashed,black] coordinates {(5,-0.5)(5,1.5)};
% https://tex.stackexchange.com/questions/218704/how-to-make-loop
% https://tex.stackexchange.com/questions/251300/changing-color-in-foreach
\foreach \n in {0, ..., 8}
{
\pgfmathsetmacro\clr{\n*10} % color
\pgfmathsetmacro\lnwdth{10-\n} % color
\addplot[smooth, blue!\clr, line width=\lnwdth pt,domain={{8-\n}:10},->] {1/((x-6+\n)*ln(x-6+\n))};
\addplot[smooth,blue!\clr,line width=\lnwdth pt, domain={-0.25:8-\n},<-] {0};
\addplot[mark=*,solid,blue!\clr] coordinates {(8-\n, {1/(2*ln(2))} )};
\addplot[mark=*,solid,blue!\clr,fill=white] coordinates {(8-\n, 0)};
}
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
However, there are some errors (current one being undefined control sequence \pgfkeyscurrentkey ->blue!\clr
). A comment in one of the linked posts mentioned something about \foreach
not working in axis
(but the 1st post I linked does use that...), and so I tried looking at \foreach not behaving in axis environment and replacing \foreach
with pgfplotsinvokeforeach
, but that didn't work (undefined control sequence \pgfplotsinvokeforeach
)