Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question

2 Answers 2

up vote 10 down vote accepted

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

share|improve this answer
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. –  Christian Feuersänger Dec 29 '11 at 14:13
    
@ChristianFeuersänger: Thanks for the information. –  Marco Daniel Dec 29 '11 at 14:21
    
@ChristianFeuersänger: I used your comment ;-) –  Marco Daniel Dec 29 '11 at 14:23

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.