我正在尝试绘制带有标记点的图,但发现有些奇怪的行为。
\pgfplotsset{every axis plot/.style={no markers, thick}}
我的文档开头就有这种情况。
如果我使用 绘制图表only marks
,标记会正确显示,但如果我同时使用only marks
和nodes near coords
,则标记会消失。以下是 MWE:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
every axis plot/.style={no markers, thick},
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[domain=-1:1, only marks, samples=3]{x};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}
\addplot+[domain=-1:1, only marks, samples=3, nodes near coords]{x};
\end{axis}
\end{tikzpicture}
\end{document}
我得到的输出如下。显然,我只需输入两个\addplot
命令即可获得两者,但第二个示例没有这样做,这是为什么呢?
答案1
通过\pgfplotset
与{}
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{
every axis plot/.style={no markers, thick},
compat=1.18
}
\begin{document}
{%<--------- begin of the group
\pgfplotsset{
every axis plot/.style={thick},
}
With \verb|every axis plot/.style={thick},|
\begin{tikzpicture}
\begin{axis}
\addplot+[domain=-1:1, only marks, samples=3, nodes near coords]{x};
\end{axis}
\end{tikzpicture}
}%<--------- end of the group
By default
\begin{tikzpicture}
\begin{axis}
\addplot+[domain=-1:1, only marks, samples=3, nodes near coords]{x};
\end{axis}
\end{tikzpicture}
\end{document}