我使用以下方法在默认设置中禁用了标记:
\pgfplotsset{every axis/.append style={
label style={font=\small},
tick label style={font=\small},
no markers,
grid
},
...
}
我以为当我添加only marks
到设置中时,它会覆盖它。它几乎可以工作,但忽略了标记设置,如下所示(我no markers
明确添加了以简化示例):
\begin{axis}[xlabel={Cost}, ylabel={Error}]
\addplot[color={red}, mark={x}, no markers, only marks]
coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
}
;
\end{axis}
如您所见,这些标记不是x
默认形状。那么,no markers
当我在默认设置中设置这些标记时,我该如何正确覆盖pgfplotsset
?
答案1
no markers
您可以通过向样式提供合适的选项来禁用/覆盖全局设置every axis plot post
(可以将其添加到axis
或\addplot
选项中)。
% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
every axis/.append style={
label style={font=\small},
tick label style={font=\small},
no markers,
grid,
},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xlabel={Cost},
ylabel={Error},
% % if you want to disable the `only marks` setting for *all* the `\addplot` command of this plot
% every axis plot post/.append style={
% only marks,
% mark=x,
% },
]
\addplot [
color={red},
every axis plot post/.append style={
only marks,
mark=x,
},
] coordinates {
(2,-2.8559703)
(3,-3.5301677)
(4,-4.3050655)
(5,-5.1413136)
(6,-6.0322865)
(7,-6.9675052)
(8,-7.9377747)
};
\end{axis}
\end{tikzpicture}
\end{document}