I want to create an array of custom defined styles and afterwards use these styles by getting them by index.
My approach so far, which isn't working:
Defining some styles:
\pgfplotsset{ redline/.style={ red }, blueline/.style={ blue } }Defining an array with the styles:
\def\mystylesarray{ {redline}, {blueline} }Using them in a plot:
\begin{tikzpicture} \begin{axis} \addplot[\mystylesarray[0]] {x}; \addplot[\mystylesarray[1]] {x^2}; \end{axis} \end{tikzpicture}
I also tried the following:
In step 2. I tried \newcommand instead of \def and using two braces around the array implementation. In step 3. I tried curly braces and normal braces. All sorts of combinations and looking for an answer online didn't bring up a solution.
Your help is appreciated.
MWE:
\documentclass{scrreprt}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{
redline/.style={
red
},
blueline/.style={
blue
}
}
\def\mystylesarray{
{redline},
{blueline}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[\mystylesarray{0}] {x};
\addplot[\mystylesarray{1}] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
pgfplotscreatecyclelist– cmhughes Sep 26 '17 at 14:52pgfplotscreatecyclelist; of course, if you're able to construct one yourself that meets your needs, it's perfectly ok to post an answer to your own question! – cmhughes Sep 26 '17 at 15:10usepackagecommand and a documentclass... – daniatic Sep 26 '17 at 15:22redlineinstead of\mystylesarray[0]. If you want consistency throughout your document I would suggest creating acycle listorcycle lists of your need and combine them with styles for different types of diagrams. – Stefan Pinnow Sep 26 '17 at 15:42cycle listthat fits the current use-case. Create a second set of this styles fitting another use-case. Then you can simply comment or uncomment them. If you want to simplify it further, add the different use-case styles to different files and load the one you want to use by\input{...}. – Stefan Pinnow Sep 26 '17 at 16:02