10

In pgfplots I can change the color of plots locally as in the example below. However is there a way to change the color for all plots in a document globally?

\documentclass{article}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
   \begin{axis}
      \addplot[color=red] coordinates{(0,0) (1,2)};
   \end{axis}
\end{tikzpicture}
\end{document}

2 Answers 2

19

A good approach is to define your own "cycle list".

The cycle list controls which colors are assigned unless your explicitly overrule the cycle list:

\documentclass{article}

\usepackage{pgfplots}

\pgfplotsset{
    cycle list={red\\yellow\\green\\},
}

\begin{document}

\begin{tikzpicture}
   \begin{axis}
      \addplot coordinates{(0,0) (1,2)};
      \addplot coordinates{(0,1) (1,3)};
   \end{axis}
\end{tikzpicture}

\end{document}

Here, the first plot has no arguments and uses the first entry of the current cycle list (which is red). The second plot uses the second entry of the cycle list (which is yellow).

This allows to define a global set of colors.

If the global cycle list contains only one entry, all plots will use this entry.

At the same time, you can still overrule color definitions by writing \addplot[<customized>] (which will ignore the cycle list entry) or \addplot+[<customized>] which will still use the cycle list, but it will append the customized options.

11

EDIT:

The following comment of Christian Feuersänger must regard

The solution is correct - but every axis plot post will append the options to every single plot. In case you want one plot to be (say) green, you would need to clear every axis plot post first

You can set this via every axis plot post

\documentclass{standalone}

\usepackage{pgfplots}
\pgfplotsset{%
 every axis plot post/.append style={red,mark=none}}

\begin{document}
\begin{tikzpicture}
   \begin{axis}
      \addplot coordinates{(0,0) (1,2)};
   \end{axis}
\end{tikzpicture}
\end{document}

In the pgfplots manual at page 236 you will find more settings. For example every axis plot no

enter image description here

3
  • 1
    The solution is correct - but every axis plot post will append the options to every single plot. In case you want one plot to be (say) green, you would need to clear every axis plot post first. Dec 29, 2011 at 14:13
  • @ChristianFeuersänger: Thanks for the information. Dec 29, 2011 at 14:21
  • @ChristianFeuersänger: I used your comment ;-) Dec 29, 2011 at 14:23

You must log in to answer this question.

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