소수의 흩어져 있는 표시와 올바른 범례만 있는 플롯

소수의 흩어져 있는 표시와 올바른 범례만 있는 플롯

선과 몇 개의 표시만으로 여러 플롯을 그리고 싶습니다. 표시의 간격이 불규칙하기 때문에 pgfplots 매뉴얼, 섹션 4.8.5(범례 모양), 159페이지 every legend image post항목에 언급된 방법을 사용했습니다. 선과 표시는 서로 다른 \addplot명령으로 생성됩니다. 이 방법의 문제는 선과 표시를 모두 표시하는 범례가 있다는 것입니다.

다음은 pgfplots 매뉴얼에 제공된 코드를 적용한 것입니다:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend image post style={mark=*}]
\addplot+[only marks,forget plot]coordinates {(0.5,-0.5) (1,-1) (1.5,-1.5)};
\addplot+[mark=none,smooth,domain=0:2]{-x};
\addlegendentry{Parabola}

\addplot+[only marks,forget plot]coordinates {(0.3,0.3) (0.45,0.45) (1.7,1.7)};
\addplot+[mark=none,smooth,domain=0:2]{x};
\addlegendentry{Parabola}
\end{axis}
\end{tikzpicture}
\end{document}

이 코드는 키에 플롯 표시를 지정할 수 있으므로 곡선이 하나만 있는 경우에도 작동합니다 legend image post style. 그러나 이것이 서로 다른 플롯 표시를 가진 여러 플롯에 어떻게 적용될 수 있는지 알고 있습니까?

답변1

대신 legend image post style각 명령에 를 제공하면 각 개별 플롯에만 적용됩니다.\addplotaxis

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[only marks,forget plot]coordinates {(0.5,-0.5) (1,-1) (1.5,-1.5)};
\addplot+[mark=none,smooth,domain=0:2,legend image post style={mark=*}]{-x};
\addlegendentry{Parabola}

\addplot+[only marks,forget plot]coordinates {(0.3,0.3) (0.45,0.45) (1.7,1.7)};
\addplot+[mark=none,smooth,domain=0:2,legend image post style={mark=square*}]{x};
\addlegendentry{Parabola}
\end{axis}
\end{tikzpicture}
\end{document}

관련 정보