I have a lot of different plots for specific configurations (c1,c2,...,c10) where I only compare some of the configurations. Lets say plot 1: (c1,c4,c10) and in the next plot (c2,c3,c5). Also I will have the same configuration in dashed or dotted multiple times in one plot (i.e. for different locations or times) like plot 3:(c1,c1 dashed, c3, c3 dashed). Now I want to create objects, storing the color, marker and linestyle information and put them in the preambel, so when I want to change a color all the plots and references change. Thank you for your help in advance!

\documentclass{standalone}

\usepackage{pgf, tikz, pgfplots}

% define the colors, here I am looking for a command, somthing like:
\definestyle{c01}{blue,mark=o}
% ...
% ... and also maybe dashed ones
\definestyle{c10_dashed}{{green!55!black,style=dashed}}


\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot[style = c01] coordinates {(0,1) (0.5,1.5) (1,1)}; % now use these here somehow
\addplot[style = c10_dashed] coordinates {(0,2) (0.5,2.5) (1,2)};
\end{axis}
\end{tikzpicture}
\end{document}
up vote 8 down vote accepted

You can define your own keys with \pgfplotsset. For example,

Sample output

\documentclass{standalone}

\usepackage{pgf, tikz, pgfplots}
\pgfplotsset{compat=1.16}

\pgfplotsset{c01/.style={blue,mark=o}}
\pgfplotsset{c10_dashed/.style={green!55!black,style=dashed}}

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot[c01] coordinates {(0,1) (0.5,1.5) (1,1)}; % now use these here somehow
\addplot[c10_dashed] coordinates {(0,2) (0.5,2.5) (1,2)};
\end{axis}
\end{tikzpicture}
\end{document}

This use the pgf keys mechanism described in the pgf documentation.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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