포인트에 대한 조각별 함수

포인트에 대한 조각별 함수

의 반복을 피하면서 조건별로 포인트를 구성하는 방법 \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}

답변1

당신이 사용할 수있는 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}

여기에 이미지 설명을 입력하세요

를 사용하면 좀 더 우아하게 만들 수 있습니다 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}

또는 목록을 작성하고 플롯할 수 있습니다. pgf가 목록을 반복할 때 작은 오류가 발생하므로 약간의 주의가 필요합니다. ...이것이 조건이 읽히고 \ifdim\i pt<0.98pt읽히지 않는 이유입니다 \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}

관련 정보