pgfplot의 범례에 사용자 정의 항목 추가

pgfplot의 범례에 사용자 정의 항목 추가

플롯 왼쪽에 있는 문자 'A'와 'B'에 대한 설명을 위해 범례에 수동 항목을 추가하고 싶습니다. 나는 그것들의 정의를 어디에 두어야할지 전혀 모릅니다.

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

따라서 범례의 "Plot E" 아래에는 "A = ..."와 같아야 합니다. 이를 수행할 수 있는 방법이 있습니까? 아니면 다른 옵션이 있나요?

답변1

\addlegendimage와 를 조합하면 \addlegendentry사용자 정의 항목을 추가할 수 있습니다. 첫 번째 목적은 그래픽 옵션을 추가하는 것이고 두 번째 목적은 설명 텍스트를 추가하는 것입니다.

귀하의 경우 작은 범례 이미지는 "A" 또는 "B"라는 텍스트일 뿐이며 설명 텍스트는... 음, 이러한 그룹을 설명합니다.

채워진 영역(작은 범례 이미지)을 사용하지 않고 단순히 텍스트가 있는 노드를 사용하는 스타일을 정의할 수 있습니다.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\pgfplotsset{
    legend image with text/.style={
        legend image code/.code={%
            \node[anchor=center] at (0.3cm,0cm) {#1};
        }
    },
}

\begin{document}

\begin{tikzpicture}
\begin{semilogyaxis}[
    domain=0:4,
]
    \addplot {x};   \addlegendentry{$x$}
    \addplot {x^2}; \addlegendentry{$x^2$}
    \addplot {x^3}; \addlegendentry{$x^3$}
    \addlegendimage{legend image with text=A}
    \addlegendentry{$= 42$}
    \addlegendimage{legend image with text=B}
    \addlegendentry{$\approx 43$}
    \addplot {x^(-1)}; \addlegendentry{$x^{-1}$}
    \addplot {x^(-2)}; \addlegendentry{$x^{-2}$}
    \addplot {x^(-3)}; \addlegendentry{$x^{-3}$}
\end{semilogyaxis}
\end{tikzpicture}

\end{document}

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

관련 정보