
pgfplots로 생성된 차트의 범례 내부에 텍스트 대신 사용자 정의 이미지(예: 플롯)를 사용할 수 있는지 궁금합니다. 특히 이번 MWC에서는 다음과 같습니다.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\tikzset{every mark/.append style={scale=0.75}}
\begin{tikzpicture}
\begin{axis}[xlabel=$x$, ymin=0, xmin=-1.1, xmax=1.1, samples=300, ylabel=$f(x)$,
smooth,
legend style={ legend cell align=left, at={(1.03, 1)}, anchor=north west}
]
\addplot coordinates {
(-1, 0)
(0, 0.5)
(1, 1)
};
\addlegendentry{Uniform(0,1)};
\addplot coordinates {
(-1, 1)
(0, 0.2)
(1, 0)
};
\addlegendentry{Exponential(1)};
\end{axis}
\end{tikzpicture}
\end{document}
아래 차트가 생성됩니다.
범례 텍스트에 균일 분포의 실제 밀도 함수를 삽입하고 싶습니다. 예를 들어 이것을 보고 싶습니다(축소)
"Uniform(0, 1)" 텍스트 대신. 물론 Exponential(1) 부분도 비슷합니다.
균일 PDF 플롯은 pgfplots(아래 MWC)로도 생성되므로 범례 항목 내에 pgfplot을 삽입할 수 있는지에 대한 질문이 있을 수 있습니다.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\tikzset{every mark/.append style={scale=0.75}}
\begin{tikzpicture}
\begin{axis}[ymin=0, xmin=0, xmax=1, ymax=2,xticklabels=none, yticklabels=none]
\addplot[color=black, fill=black] (x,1) \closedcycle;
\end{axis}
\end{tikzpicture}
\end{document}
나중에 편집
Torbjorn이 제안한 솔루션이 작동합니다. 그것은 내가 원하는 것을 수행합니다:
이전에 컴파일된 파일을 포함하지 않고 모든 것을 즉석에서 생성할 수 있는 또 다른 가능성이 있는지 알아보기 위해 질문을 열어 보겠습니다.
답변1
(이것은 내 초기 답변을 완전히 다시 작성한 개정판입니다.)
범례 항목의 설명을 수정하려면 \addlegendentry
, legend entries
또는 를 사용할 수 있습니다 \legend
. 결과적으로 @Torbjorns 답변이 갈 길입니다.
그러나 범례 텍스트에 작은 그림을 자유롭게 삽입할 수 있습니다. 텍스트에는 제한이 없습니다. 이를 위해 \tikz ... ;
"Uniform" 대신 간단히 쓸 수 있습니다.
다음은 @Torbjorns 답변과 어느 정도 적합한 이미지를 조합하려는 시도를 기반으로 한 접근 방식입니다.
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\tikzset{every mark/.append style={scale=0.75}}
\begin{tikzpicture}
\begin{axis}[xlabel=$x$, ymin=0, xmin=-1.1, xmax=1.1, samples=300, ylabel=$f(x)$,
smooth,
legend style={ legend cell align=left, at={(1.03, 1)}, anchor=north west}
]
\addplot coordinates {
(-1, 0)
(0, 0.5)
(1, 1)
};
\addlegendentry{
\begin{tikzpicture}
\fill[draw] (0cm,0cm) rectangle (0.6cm,-0.15cm);
\draw (0cm,0cm) rectangle (0.6cm,+0.15cm);
\end{tikzpicture}
}
\addplot coordinates {
(-1, 1)
(0, 0.2)
(1, 0)
};
\addlegendentry{
\tikz\draw[mark=none,samples=11,domain=-2.5:2.5,xshift=1em,yshift=-0.05cm,xscale=0.015,yscale=0.03] plot (\x,{exp(-(\x)^2)});
}
\end{axis}
\end{tikzpicture}
\end{document}
답변2
직접적인 대답은 아니지만 최소한 해결 방법은 다음과 같습니다. 범례 항목에 사용할 수 있으므로 \includegraphics
먼저 균일 분포를 생성하는 코드를 컴파일한 다음 사용할 수 있습니다.
\addlegendentry{\includegraphics[width=1cm]{FilenameOfPDFwithUniformDist}};
범례에 이미지를 추가합니다.