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 have a legend with the option area legend to draw a little rectangle in the legend instead of a line segment. There is a border around the rectangle I would like to either remove or make the same color as the actual rectangle. How is this done?

share|improve this question
    
How do you want some help? You didn't even provide any of the command used to draw this area! –  Lionel MANSUY Feb 25 '13 at 13:55
    
the command is area legend –  Man of One Way Feb 25 '13 at 13:55
    
It does not: \addplot +[fill=grey0, draw=none] –  Man of One Way Feb 25 '13 at 13:58
    
@ManofOneWay using your command gives me "undefined control sequence" –  Lionel MANSUY Feb 25 '13 at 13:59
    
@Jake Noticed. Thank you –  Man of One Way Feb 25 '13 at 14:02
add comment

2 Answers

up vote 3 down vote accepted

To hide the border both in the plot and in the legend, you should use draw opacity=0 in the \addplot options instead of draw=none:

\documentclass[border=5mm] {standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot [fill=yellow,draw opacity=0, area legend] coordinates {(0,0) (2,1) (4,1)} \closedcycle;
\addlegendentry{Plot}
\end{axis}
\end{tikzpicture}

\end{document}
share|improve this answer
1  
That worked perfectly. Thank you! –  Man of One Way Feb 25 '13 at 14:01
add comment

Another possibility is to change the area legend style so that draw=none actually takes effect. (Example taken from the pgfplots manual, page 173.)

Code

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
    /pgfplots/area legend/.style={%
        /pgfplots/legend image code/.code={%
            \fill[##1] (0cm,-0.1cm) rectangle (0.6cm,0.1cm);
        }%
    },
}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    area legend,
    axis x line=bottom,
    axis y line=left,
    domain=0:1,
    legend style={at={(0.03,0.97)},anchor=north west},
    axis on top,xmin=0]
\addplot[
    pattern=crosshatch dots,
    pattern color=blue,
    draw=none,
    samples=500] {sqrt(x)} \closedcycle;
\addplot[
    pattern=crosshatch,
    pattern color=blue!30!white,
    draw=blue!30!white] {x^2} \closedcycle;
\addplot[red,line legend] coordinates {(0,0) (1,1)};
\legend{$\sqrt x$,$x^2$,$x$}
\end{axis}
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer
    
Could you post this as a bug report? –  Jake Feb 25 '13 at 14:06
1  
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.