
プロットの左側にある文字「A」と「B」の説明を凡例に手動で追加したいのですが、それらの定義をどこに置くべきか他にわかりません。
したがって、凡例の「Plot E」の下には「A = ...」のような表示がされるはずです。これを行う方法はありますか? または、別のオプションがありますか?
答え1
\addlegendimage
とを組み合わせると\addlegendentry
、カスタム エントリを追加できます。最初の目的はグラフィック オプションを追加することであり、2 番目の目的は説明テキストを追加することです。
あなたの場合、小さな凡例画像にはおそらく「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}