1

I'm trying to make a plot with labeled points and am seeing some strange behavior. I have \pgfplotsset{every axis plot/.style={no markers, thick}} at the start of my document.

If I make a plot with only marks, the marks show up correctly, but if I have both only marks and nodes near coords, then the marks disappear. Here's a 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}

The output I get is below. Obviously, I can just put two \addplot commands in to get both, but is there a reason the second example doesn't do it?

enter image description here

3
  • 1
    remove no markers in every axis plot/.style={no markers, thick}, and it's better add compat=1.18
    – pascal974
    Commented Jun 24, 2023 at 6:13
  • I have no markers in every axis plot/.style because I have a very long document with lots and lots of plots, and in almost all of them, I actually don't want markers. So, I'm really wanting to know how to override that in a particular plot.
    – Janet
    Commented Jun 26, 2023 at 13:34
  • I posted an answer
    – pascal974
    Commented Jun 27, 2023 at 13:30

1 Answer 1

0

By putting \pgfplotset in a group with {}

\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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .