
So konstruieren Sie Punkte nach Bedingungen und vermeiden dabei Wiederholungen \addplot
.
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\pgfplotsinvokeforeach{0.3,0.4,...,1} {
\addplot coordinates { #1 < 1 ? (#1,#1) : (5,5) }; % if \i < 1 then put (x,y) on axis, else put (5,5) point on axis
}
\end{axis}
\end{tikzpicture}
\end{document}
Antwort1
Sie können verwenden samples at
.
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[blue,mark=*,samples at={0.3,0.4,...,1}]
({ifthenelse(x < 1,x,5)},{ifthenelse(x < 1,x,5)}); % if \i < 1 then put (x,y) on axis, else put (5,5) point on axis
\end{axis}
\end{tikzpicture}
\end{document}
was mit etwas eleganter gemacht werden kann declare function
,
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[declare function={f(\x)=ifthenelse(\x<1,\x,5);}]
\begin{axis}
\addplot[blue,mark=*,samples at={0.3,0.4,...,1}]
({f(x)},{f(x)}); % if \i < 1 then put (x,y) on axis, else put (5,5) point on axis
\end{axis}
\end{tikzpicture}
\end{document}
Alternativ können Sie eine Liste erstellen und sie grafisch darstellen. Dabei ist etwas Vorsicht geboten, da beim Durchlaufen von Listen mit pgf ...
kleine Fehler auftreten, weshalb die Bedingung lautet \ifdim\i pt<0.98pt
und nicht \ifdim\i pt<1pt
.
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\edef\mylst{}
\pgfplotsforeachungrouped \i in {0.3,0.4,...,1} {%
\ifdim\i pt<0.98pt
\edef\mylst{\mylst (\i,\i)}
\else
\edef\mylst{\mylst (5,5)}
\fi
}%
\addplot coordinates {\mylst};
\end{axis}
\end{tikzpicture}
\end{document}