[Tex/LaTex] Remove border around area legend rectangle

legendpgfplots

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?

Best Answer

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}