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.

Is it possible to combine two cycle lists? That is, is it possible to apply simultaneously several cycle lists to a common plot without the last list overriding the others (that is, getting a behaviour not unlike the /.style append commands)?

For instance, I have a first list of markers and a second of colours:

\documentclass{article}

\begin{document}

\pgfplotscreateplotcyclelist{list1}{%
{},
{mark=x},
{mark=+}}

\pgfplotscreateplotcyclelist{list2}{%
{color=red},
{color=blue},
{color=green}}



\begin{tikzpicture}
\begin{axis}
% Mising commands before plot 1
\addplot {x}; % should be red and have no marker
\addplot {x+1}; % should be blue and have `x' marker
\addplot {x+2}; % should be green and have `+' marker

% plot 2
\pgfplotsset{cycle list name=list1}
\addplot {2*x}; % is red and has default marker
\addplot {2*x+1}; % is blue and has default marker
\addplot {2*x+2}; % is green and has default marker


% plot 3
\pgfplotsset{cycle list name=list2}
\addplot {-x}; % is default colour and has no marker
\addplot {-x+1}; % is default colour and has `x' marker
\addplot {-x+2}; % is default colour and has `+' marker
\end{axis}

\end{tikzpicture}
\end{document}

I want to use sometimes only the markers, sometimes only the colours and sometimes both simultaneously. This is different from cycle multi list which increment first the last list and then the first at each reset of the second. For sure, I can create a third list to manually combine list1 and list2 but I am wondering if that can be achieved more efficiently?

Such a feature would come in handy when having using list for several features (colour, marker, line style etc.) in a long document and using them in various combinations. In this case, writing all the combinations is cumbersome and changing, say, one colour means tracking it done in every combinations.

share|improve this question
    
Welcome to TeX.SE. While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. That way those trying to help can focus on solution as opposed to setting up the problem test case. –  Peter Grill Feb 28 '12 at 17:14
add comment

2 Answers

up vote 5 down vote accepted

Yes: simply change the cycle list name before the (group of) plots:

\documentclass{article}

\begin{document}

\pgfplotscreateplotcyclelist{list1}{%
{},
{mark=x},
{mark=+}}

\pgfplotscreateplotcyclelist{list2}{%
{color=red},
{color=blue},
{color=green}}

\begin{tikzpicture}
    \begin{axis}
    \pgfplotsset{cycle list name=list1}
    \addplot {x};
    \addplot {x+1};

    \pgfplotsset{cycle list name=list2}
    \addplot {5-x};
    \addplot {6-x};
    \end{axis}
\end{tikzpicture}
\end{document}

Both will be incremented simultaneously. In fact, none of them is "incremented", but the current plot index is used as lookup index into the current list. And the \pgfplotsset changes the "current list".

share|improve this answer
    
I edited my question for clarity : the word ìncrementing' was ill chosen. Your exemple gives two black increasing lines, one with no marker, one with x' marker and a red and a green decreasing curve (with no marker). I would rather have a red with no marker, a blue with x' marker and a green with `+' marker with the possibility to use the same list to have onl coloured ones or only marked ones. –  Alfred M. Feb 29 '12 at 7:07
add comment

I've found a partial expedient to my problem. The trick is to do it the other way around : write the combined list and disable the features one does not want. It works well for markers but not exactly for colors (black instead of default). It is also less usefull because when there are several marker lists or colour lists one has to write several combined lists.

\documentclass{article}
\tikzset{no colour/.style={color=black}}
\tikzset{no marker/.style={maker={}}}
\begin{document}

\pgfplotscreateplotcyclelist{list3}{%
{color=red},
{color=blue,mark=x},
{color=green,mark=+}}



\begin{tikzpicture}
\begin{axis}
% plot 1
\addplot {x}; % is red and has no marker
\addplot  {x+1}; % is blue and has `x' marker
\addplot  {x+2}; % is green and has `+' marker

% plot 2
\addplot+[no marker] {2*x}; % is red and has default marker
\addplot+[no marker] {2*x+1}; % is blue and has default marker
\addplot+[no marker] {2*x+2}; % is green and has no marker


% plot 3
\addplot+[no colour] {-x}; % is black and has no marker
\addplot+[no colour] {-x+1}; % is black and has `x' marker
\addplot+[no colour] {-x+2}; % is black and has `+' marker
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
add comment

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.