1

Due to all the maintenance after changing a color in a list, I tried to define just one cycle list so I do not have to update all my lists anymore. It is all in all an annoyingly huge amount of time, which I rather spend on something else.

I already worked out a solved MWE and this is more of a question for reassurance. But if others are looking for a similar solution, this question might help them. I suppose there is one possible drawback to it: the font is also colored.

So: is this aproper way to define one single cycle list for the use with pgfplots?

Picture

enter image description here

MWE

\documentclass[
a4paper
]{scrartcl}

\usepackage{
amsmath,
tikz,
pgfplots,
pgfplotstable,
}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepgfplotslibrary{groupplots}

\pgfplotstableread[col sep=comma]{
Process,ValueA,ValueB
1,66,70
2,66,40
3,24,20
4,52,60
5,64,30
6,37,30
}{\tableabcdef}

\pgfplotscreateplotcyclelist{mycolorlisttest}{%
blue!60!black,fill=blue!60!black,every mark/.append style={fill=blue!60!black},mark=*\\%1
red!70!black,fill=red!70!black,every mark/.append style={fill=red!70!black},mark=*\\%2
green!70!black,fill=green!70!black,every mark/.append style={fill=green!70!black},mark=*\\%3
gray,fill=gray,fill=gray,fill=gray,every mark/.append style={fill=gray},mark=*\\%4
orange,fill=orange,every mark/.append style={fill=orange},mark=*\\%5
brown!80!black,fill=brown!80!black,every mark/.append style={fill=brown!80!black},mark=*\\%6
green,fill=green,every mark/.append style={fill=green},mark=*\\%7
violet!80!black,fill=violet!80!black,every mark/.append style={fill=violet!80!black},mark=*\\%8
black,fill=black,every mark/.append style={fill=black},mark=*\\%9
teal,fill=teal,every mark/.append style={fill=teal},mark=*\\%10
magenta!70!black,fill=magenta!70!black,every mark/.append style={fill=magenta!70!black},mark=*\\%11
yellow!90!black,fill=yellow!90!black,every mark/.append style={fill=yellow!90!black},mark=*\\%12
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{axis}[
xlabel={Force in N},
ylabel={Process},
%
xbar,
%
xmin=0,
%
enlarge x limits={rel={0.2}, upper},
%
ytick=data,
nodes near coords,
nodes near coords align={right=3pt},
every node near coord/.append style={fill=white, font=\footnotesize, inner sep=1pt},
%
cycle list name=mycolorlisttest,
no markers
]
\addplot+ table [x=ValueA, y=Process] {\tableabcdef};
\addplot+ table [x=ValueB, y=Process] {\tableabcdef};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

SOLUTION

\documentclass[
a4paper
]{scrartcl}

\usepackage{
amsmath,
tikz,
pgfplots,
pgfplotstable,
}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepgfplotslibrary{groupplots}

\pgfplotstableread[col sep=comma]{
Process,ValueA,ValueB
1,66,70
2,66,40
3,24,20
4,52,60
5,64,30
6,37,30
}{\tableabcdef}

\tikzset{
meinemarkfarben/.style={
mark=*,
draw=#1,
fill=#1,
every mark/.append style={fill=#1}}
}

\pgfplotscreateplotcyclelist{aaaaaaa}{%
meinemarkfarben={yellow!60!black}\\%1
meinemarkfarben={red!70!black}\\%2
meinemarkfarben={green!70!black}\\%3
meinemarkfarben={gray}\\%4
meinemarkfarben={orange}\\%5
meinemarkfarben={brown!80!black}\\%6
meinemarkfarben={green}\\%7
meinemarkfarben={violet!80!black}\\%8
meinemarkfarben={black}\\%9
meinemarkfarben={teal}\\%10
meinemarkfarben={magenta!70!black}\\%11
meinemarkfarben={yellow!90!black}\\%12
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]
\begin{axis}[
xlabel={Force in N},
ylabel={Process},
%
xbar,
%
xmin=0,
%
enlarge x limits={rel={0.2}, upper},
%
ytick=data,
nodes near coords,
nodes near coords align={right=3pt},
every node near coord/.append style={fill=white, font=\footnotesize, inner sep=1pt},
%
cycle list name=aaaaaaa,
no markers
]
\addplot+ table [x=ValueA, y=Process] {\tableabcdef};
\addplot+ table [x=ValueB, y=Process] {\tableabcdef};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

Picture of Solution

enter image description here

  • If you \usepackage[svgnames]{xcolor} before \usepackage{tikz} you can access a lot more colors by name. – John Kormylo Jul 28 '14 at 13:27
  • @henry please use a document class not restricted to other packages. For MWE article is perfect unless it is a question about the document class. – zeroth Jul 28 '14 at 14:09
1

This should be done by wrapping it around a custom style. I am not totally sure what you want?

Do this:

\tikzset{
  my mark set/.style={
    draw=#1,
    fill=#1,
    every mark/.append style={fill=#1}
  }
}

Then you can do:

\pgfplotscreateplotcyclelist{mycolorlisttest}{%
  my mark set=blue!60!black,mark=*\\%1
  my mark set=red!70!black,mark=*\\%2
  ...
}

You can of course utilise the special setting with the args such as:

\tikzset{
  my mark set/.style 2 args={
    mark=#1,
    draw=#2,
    fill=#2,
    every mark/.append style={fill=#2}
  }
}

and then do:

\pgfplotscreateplotcyclelist{mycolorlisttest}{%
  my mark set={*}{blue!60!black}\\%1
  my mark set={*}{red!70!black}\\%2
  ...
}
1

It can be done with macros after all, but no real advantage over using /.style

\documentclass[a4paper]{scrartcl}

\usepackage{amsmath,tikz,pgfplots,pgfplotstable}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepgfplotslibrary{groupplots}

\pgfplotstableread[col sep=comma]{
Process,ValueA,ValueB
1,66,70
2,66,40
3,24,20
4,52,60
5,64,30
6,37,30
}{\tableabcdef}

\newcommand*{\cycleitem}[1]% #1 = color
{#1,fill=#1,every mark/.append style={fill=#1},mark=*}

\newcommand{\cyclelist}{% list stored as a macro
{\cycleitem{blue!60!black}},%1
{\cycleitem{red!70!black}},%2
{\cycleitem{green!70!black}},%3
{\cycleitem{gray}},%4
{\cycleitem{orange}},%5
{\cycleitem{brown!80!black}},%6
{\cycleitem{green}},%7
{\cycleitem{violet!80!black}},%8
{\cycleitem{black}},%9
{\cycleitem{teal}},%10
{\cycleitem{magenta!70!black}},%11
{\cycleitem{yellow!90!black}}%12
}

\begin{document}
\begin{center}
\begin{tikzpicture}[font=\small]

\begin{axis}[
xlabel={Force in N},
ylabel={Process},
%
xbar,
%
xmin=0,
%
enlarge x limits={rel={0.2}, upper},
%
ytick=data,
nodes near coords,
nodes near coords align={right=3pt},
every node near coord/.append style={fill=white, font=\footnotesize, inner sep=1pt},
%
cycle list/.expanded={\cyclelist},% uses macro instead of name
no markers
]
\addplot+ table [x=ValueA, y=Process] {\tableabcdef};
\addplot+ table [x=ValueB, y=Process] {\tableabcdef};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
  • Great idea! Doesn't work though: ! Use of \pgfplots@addplotimplAPPEND@ doesn't match its definition. \pgfutil@ifnextchar ...1\def \pgfutil@reserved@a { #2}\def \pgfutil@reserved@... l.81 \addplot+ t. :( – henry Jul 28 '14 at 13:53
  • 1
    Okay, it works now. BTW, \pgfplotscreateplotcyclelist aso stores the list as a macro using \csname and a lot of @ symbols. – John Kormylo Jul 30 '14 at 4:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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