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.

In order to fill the area between two complex curves I use tables and the vertcat command (see Fill between two curves in pgfplots.).

Now I don't want the plotted area to appear in my legend, just the two curves. Is there any command to prevent the yellow area plot from being added to my legend? this could be a minimal example:

\documentclass{article} \usepackage{pgfplots} 
\begin{document} \begin{tikzpicture}
  \begin{axis}[area style,axis on top]
    \addplot+[mark=none,fill=yellow,draw=none] {0.1*x^2} \closedcycle;
    \addplot[mark=none,draw=red,line legend] {0.1*x^2};
    \addplot[mark=none,draw=blue,line legend] {0.0*x^2};
    \legend{red curve,blue curve};
    % \legend{\empty,red curve,blue curve};
  \end{axis}
\end{tikzpicture} \end{document}

With this legend{...}-command the last plot is skipped, an additional \empty doesn't help, too.

Sadly, drawing the first to plots together with fill=yellow,draw=red is not an option for me. Does anybody know any inside hacks? As far as I know, there is no command shown in the manual. Thanks in advance.

share|improve this question
add comment

1 Answer 1

up vote 21 down vote accepted

Adding the option forget plot to the plot you do not want shown does the trick.

\documentclass{article} \usepackage{pgfplots} 
\begin{document} \begin{tikzpicture}
  \begin{axis}[area style,axis on top]
    \addplot+[mark=none,fill=yellow,draw=none,forget plot] {0.1*x^2} \closedcycle;
    \addplot[mark=none,draw=red,line legend] {0.1*x^2};
    \addplot[mark=none,draw=blue,line legend] {0.0*x^2};
    \legend{red curve,blue curve};
  \end{axis}
\end{tikzpicture} \end{document}

forget plot pgfplots


Alternatively, you could use an empty entry in the \legend list for the plot you want to exclude from the legend:

\documentclass{article}
\usepackage{pgfplots} 
\begin{document}
\begin{tikzpicture}
  \begin{axis}[axis on top]
    \addplot [area style,fill=yellow,draw=none] {0.1*x^2} \closedcycle;
    \addlegendentry{}
    \addplot [draw=red] {0.1*x^2};
    \addplot [draw=blue] {0.0*x^2};
    \legend{,red curve,blue curve};
  \end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer
1  
thanks for that very fast answer! –  kromuchi Mar 29 '11 at 13:35
    
very nice, thank you! –  tim Feb 2 at 12:11
    
Is forget plot the only way to avoid a legend. The reason I ask is because forget plot has other side effects like for example that symbol and color counter doesn't increase. –  alfC Feb 3 at 10:01
    
@alfC: You can use empty entries in the \legend list to exclude plots. I've edited my answer. –  Jake Feb 3 at 10:06
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.