我有以下 PGFPlots(小样本)。
\documentclass[11pt, a4paper, twoside]{scrreprt} % [11pt, parskip]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[colorlinks = true, citecolor=black, filecolor=black, linkcolor=black, urlcolor=black, linktocpage=true]{hyperref}
\usepackage{tikz} % Zeichnungen
\usepackage{pgfplots} % Diagramme
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scatter/classes={a={blue},b={mark=triangle*,blue},c={mark=square*,blue}},
every x tick scale label/.style={at={(xticklabel cs:1)},anchor=south west},
every axis plot/.append style={mark=none} ,
legend pos=north east,
legend style={draw=none, fill=none},
]
\addplot [scatter, only marks, scatter src=explicit symbolic]
coordinates{
(1,1) [a]
(1,2) [b]
(1,3) [c]
(2,2) [a]
};
\addplot [color=red]
coordinates{
(1,1)
(2,2)
};
\legend{~,~,Data,Fit}
\end{axis}
\end{tikzpicture}
\end{document}
我现在想要以下样式的图例(一行):
标准标记,三角形,正方形数据
我更新了示例,因为我得到了一些新信息,我还必须将 Fit 放入数据中。在图片中,您可以找到我希望图例看起来是什么样子的示例。
答案1
人们总是可以使用\addlegendentry
和将图例拼凑在一起\addlegendimage
。然后就可以想出任何legend image code
自己喜欢的东西。这是一个例子,当然可以改进。为了找到标记的合适坐标,我line legend
在手册中查找了代码。
\documentclass[11pt, a4paper, twoside]{scrreprt} % [11pt, parskip]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[colorlinks = true, citecolor=black, filecolor=black, linkcolor=black, urlcolor=black, linktocpage=true]{hyperref}
\usepackage{tikz} % Zeichnungen
\usepackage{pgfplots} % Diagramme
\pgfplotsset{%
my legend/.style={legend image code/.code={%
\node[##1,anchor=west] at (0cm,0cm){\pgfuseplotmark{*}};
\node[##1] at (0.3cm,0cm){\pgfuseplotmark{triangle*}};
\node[##1,anchor=east] at (0.6cm,0cm){\pgfuseplotmark{square*}};
}},%
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scatter/classes={a={blue},b={mark=triangle*,blue},c={mark=square*,blue}},
every x tick scale label/.style={at={(xticklabel cs:1)},anchor=south west},
every axis plot/.append style={mark=none} ,
legend pos=north east,
legend style={draw=none, fill=none},
]
\addlegendimage{my legend,blue}
\addlegendentry{Data}
\addlegendimage{line legend,red,line width=1pt}
\addlegendentry{Fit}
\addplot [scatter, only marks, scatter src=explicit symbolic]
coordinates{
(1,1) [a]
(1,2) [b]
(1,3) [c]
(2,2) [a]
};
\addplot [color=red]
coordinates{
(1,1)
(2,2)
};
\end{axis}
\end{tikzpicture}
\end{document}