我想在图例中添加额外的信息。我在 MWE 中完成了此操作,我创建了一个虚拟图以便在图例中添加额外的信息。如何在不创建假 \addplot 的情况下完成此操作?谢谢。
\documentclass[letterpaper]{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymax = 3000,
ymin = -3000,
height=9cm,
width=9cm,
grid=major,
]
\addplot {-x^5 - 242};
\addlegendentry{model}
\addplot coordinates {
(-4.77778,2027.60977)
(-3.55556,347.84069)
(-2.33333,22.58953)
(-1.11111,-493.50066)
(0.11111,46.66082)
(1.33333,-205.56286)
(2.55556,-341.40638)
(3.77778,-1169.24780)
(5.00000,-3269.56775)
};
\addlegendentry{estimate}
\addplot[only marks,white] coordinates {(-1,-15000)}; % dummy plot to add extra legend entry.....
\addlegendentry{Additional Information}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
神奇的命令行是
\addlegendimage{empty legend}
我也建议添加\pgfplotsset{compat=1.16}
,但这里不需要。
\documentclass[letterpaper]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}% <-added but not necessary
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymax = 3000,
ymin = -3000,
height=9cm,
width=9cm,
grid=major,
]
\addplot {-x^5 - 242};
\addlegendentry{model}
\addplot coordinates {
(-4.77778,2027.60977)
(-3.55556,347.84069)
(-2.33333,22.58953)
(-1.11111,-493.50066)
(0.11111,46.66082)
(1.33333,-205.56286)
(2.55556,-341.40638)
(3.77778,-1169.24780)
(5.00000,-3269.56775)
};
\addlegendentry{estimate}
\addlegendimage{empty legend}
\addlegendentry{Additional Information}
\end{axis}
\end{tikzpicture}
\end{document}