
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)の部分も同様です。
Uniform 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}};
凡例に画像を追加します。