# Matlab2tikz adds extra legend entries [closed]

The legend from a boxplot figure is not being created properly.

I get this:

Instead of thiS: But really only need 2 legend entries. Any Ideas why all the objects in this plot are being given legend entries when in Matlab there are only 2 light blue=4ACH and dark blue=6ACH.

How do I make the two blue boxes using tikz code? \addlegendentry doesn't work because the boxplots are not plot items but filled objects defined by tables of coordinates

MVE

\documentclass{amsart}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{subfig}
%\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode} %matlab to latex s
\usepackage{tikz,pgfplots}
\pgfplotsset{plot coordinates/math parser=false}
\usetikzlibrary{plotmarks}
\begin{document}

\definecolor{mycolor1}{rgb}{0.6,0.8,1}
\definecolor{mycolor2}{rgb}{0,0.2,0.6}

\begin{tikzpicture}

\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmin=0.5, xmax=1.5,
xtick={1},
xticklabels={Direct Care,Housekeeping,Mealtimes,Medication Round,Miscellaneous,Personal Care},
ymin=-10, ymax=100,
ytick={0,10,20,30,40,50,60,70,80,90,100},
ylabel={Normalised cfu (Y) values},
legend style={draw=black,fill=white,legend cell align=left}
]

color=black,
solid
]
table{
0.755 0
0.895 0
};

color=black,
solid
]
table{
0.755 0
0.895 0
};

color=black,
solid,
line width=1.0pt
]
table{
0.685 0
0.965 0
};

color=blue,
only marks,
mark=*,
mark options={solid,fill=mycolor1,draw=black}
]
table{
0.825 10.0567798116818
};
color=black,
dotted
]
table{
0.825 0
0.825 0
};
color=black,
solid
]
table{
0.755 0
0.895 0
};

color=black,
solid
]
table{
0.755 0
0.895 0
};

color=black,
solid,
line width=1.0pt
]
table{
0.685 0
0.965 0
};

color=blue,
only marks,
mark=*,
mark options={solid,fill=mycolor1,draw=black}
]
table{
0.825 10.0567798116818
};

color=black,
dotted
]
table{
1.175 0
1.175 0
};

color=black,
solid
]
table{
1.105 0
1.245 0
};

color=black,
solid
]
table{
1.105 0
1.245 0
};

color=black,
solid,
line width=1.0pt
]
table{
1.035 0
1.315 0
};

color=blue,
only marks,
mark=*,
mark options={solid,fill=mycolor2,draw=black}
]
table{
1.175 10.6896518156056
};

\end{axis}
\end{tikzpicture}%
\end{document}

-

## closed as unclear what you're asking by Paul Gessler, Christian Hupfer, Papiro, egreg, Svend TveskægFeb 8 '15 at 22:21

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Every \addlegendentry will produce a legend entry. This is more Matlab2TikZ’ wrong-doing than pgfplots’. Would manually removing the additional \addlegendentrys be a solution? – Qrrbrbirlbel Mar 16 '13 at 4:00
This is what I thiught too, but I cant seem to find the correct legend entry fornthe blue boxes. Can you replicate those using tikz commands of some sort? – HCAI Mar 16 '13 at 8:03
You can use area legend for that. See the manual. – percusse Mar 17 '13 at 12:22
@percusse tex.stackexchange.com/questions/62262/legend-in-tikzpicture Shows a good example of your suggestion and it partially works. Is it possible to automatically position the legend depending on the size of the graph? I have 100 graphs of different sizes and it would be very teadious to work out the coordinates of the upper right corner for each one. Any thoughts? If you make this an answer I'll give you thumbs up. Cheers – HCAI Mar 17 '13 at 14:04
Have you been able to solve this? I wasn't able to reproduce the problem, could you post the Matlab code as well? (You can replace your data with some random numbers.) – Torbjørn T. Nov 3 '13 at 9:49