1

When using pgfplots, is there a way to set the style for every node on a plot for a particular axis? I'm currently setting the style for each plot, but I've been unable to do the same for each node along a plot. Below is a MWE where the node should be black,but it is the same color as the plot.

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      every axis plot/.append style={line width=0.95pt, color=blue, samples=255},
      every axis plot node/.style={color=black},
      ]
      \addplot[<->] expression[domain=0:4]{x^2} node[pos=0.5, below] {$x^2$};
    \end{axis}
  \end{tikzpicture}
\end{document}
1
  • 1
    Does ` \begin{tikzpicture}[nodes={text=black}]` solve your problem? Commented Sep 22, 2024 at 12:45

1 Answer 1

1

You need to say nodes={text=black}:

  • at \begin{tikzpicture}[nodes={text=black}] or
  • \begin{axis}[ ... nodes={text=black}, ...]

BTW:

  • I do not find a key every axis plot node/.style={...} (?)
  • I think you do not need append style at every axis plot/.append style={...}, but whatever.

enter image description here

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
nodes={text=black}, 
      every axis plot/.append style={line width=0.95pt, color=blue, samples=255,},
%      every axis plot node/.style={color=black},
      ]
      \addplot[<->] expression[domain=0:4]{x^2} node[pos=0.5, below] {$x^2$};
    \end{axis}
  \end{tikzpicture}
\end{document}
3
  • 1
    @cls with text=black in èvery axis plot` this works too. Commented Sep 22, 2024 at 14:36
  • Sure, but I thought you want to have that 'very globally'. Commented Sep 22, 2024 at 14:39
  • That works and is way simpler than I was making it out to be. The every axis plot isn't relevant in this example other than I thought that setting the style for nodes would be like that, which is where my guess of every axis plot node came from. Commented Sep 22, 2024 at 17:45

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.