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.

I am using cycle lists and the \addplot+ command to plot lines in different styles. I would like to plot several things using each style, however, like this:

% Plot using style 1
\addplot+ coordinates {...};
\addplot coordinates {...};
\addlegendentry{Style 1}

% Plot using style 2
\addplot+ coordinates {...};
\addplot coordinates {...};
\addlegendentry{Style 2}

How can I do this?

share|improve this question

2 Answers 2

up vote 13 down vote accepted

forget plot key is the usual way to do this but \addlegendentry{} does not choose which addplot command it comes after. You have to draw the to-be-legended(!?) plots consecutively at the beginning. So you can collate the plots such that you draw them 1-2-3,1-2-3, in terms of style as follows

\begin{tikzpicture}
\begin{axis}
% Plot using style 1
\addplot {ln(x)};\addlegendentry{Style 1}
\addplot {3*x};\addlegendentry{Style 2}

\pgfplotsset{cycle list shift=-2} % Goes two styles back
\addplot {0.5*x}; %Style 1
\addplot {2*x}; %Style 2
\end{axis}
\end{tikzpicture}

enter image description here

share|improve this answer
    
be warned: {cycle list shift} is not a function but an offset so it does not affect the internel counter! So to draw another two plots with the same style use \pgfplotsset{cycle list shift=-4} (and not -2 agian) –  Thomas Jul 1 at 17:02
1  
@Thomas That's the designated behavior, from the manual; Remember that i is the index of the current \addplot command (starting with 0). –  percusse Jul 2 at 9:16

Never mind, I seem to have stumbled upon the answer myself in the pfdplots manual section 4.24 "Miscellaneous Options", specifically the forget plot option:

% Plot using style 1
\addplot+ [forget plot] coordinates {...};
\addplot+ coordinates {...};
\addlegendentry{Style 1}

% Plot using style 2
\addplot+ [forget plot] coordinates {...};
\addplot+ coordinates {...};
\addlegendentry{Style 2}
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.