0

I have created a Matlab figure. I have converted the figure to a .tikz file using the matlab2tikz script. The legend of my .tikz - file, however, is different from the Matlab-figure. For example, the second legend entry refers to a + marker. In the legend, there should only be the + sign.

However, for some reason, there is an extra line in every legend entry, which makes everything hard to read. See the picture below (the first entry of the second column - you can barely recognize the +). Why do these lines occur?

% This file was created by matlab2tikz.
%
%The latest updates can be retrieved from
%  http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz
%where you can also make suggestions and rate matlab2tikz.
%
\definecolor{mycolor1}{rgb}{0.00000,0.44700,0.74100}%
\definecolor{mycolor2}{rgb}{0.85000,0.32500,0.09800}%
\definecolor{mycolor3}{rgb}{0.92900,0.69400,0.12500}%
\definecolor{mycolor4}{rgb}{0.49400,0.18400,0.55600}%
\definecolor{mycolor5}{rgb}{0.46600,0.67400,0.18800}%
\definecolor{mycolor6}{rgb}{0.30100,0.74500,0.93300}%
%
\begin{tikzpicture}

\begin{axis}[%
width=4.0in,
height=2.0in,
at={(0.758in,2.013in)},
scale only axis,
xmin=0,
xmax=55,
xtick={5,10,15,20,25,30,35,40,45,50},
xticklabels={{1},{2},{3},{4},{5},{6},{7},{8},{9},{10}},
xlabel style={font=\color{white!15!black}},
xlabel={cases},
ymin=10,
ymax=60,
ylabel style={font=\color{white!15!black}},
ylabel={power [dBm]},
axis background/.style={fill=white},
axis x line*=bottom,
axis y line*=left,
xmajorgrids,
ymajorgrids,
legend style={at={(0.5,-0.2)}, anchor=north, legend columns=2, legend cell align=left, align=left, draw=white!15!black}
]
\addplot [color=mycolor1, line width=1.0pt, draw=none, mark size=3.0pt, mark=square, mark options={solid, red}]
  table[row sep=crcr]{%
5   50.25\\
10  49.1\\
15  49.41\\
20  47.99\\
25  48.08\\
30  47.88\\
35  47.73\\
40  49.03\\
45  50.1\\
50  51.05\\
};
\addlegendentry{output power 1st}

\addplot [color=mycolor2, line width=1.0pt, draw=none, mark size=3.0pt, mark=+, mark options={solid, blue}]
  table[row sep=crcr]{%
5   48.02\\
10  48.01\\
15  48\\
20  47.94\\
25  48.02\\
30  47.96\\
35  48.03\\
40  48.01\\
45  47.99\\
50  47.96\\
};
\addlegendentry{IMAL output power 1st}

\addplot [color=mycolor3, line width=1.0pt, draw=none, mark size=3.0pt, mark=o, mark options={solid, black}]
  table[row sep=crcr]{%
5   41.947\\
10  44.268\\
15  46.084\\
20  47.385\\
25  48.036\\
30  47.577\\
35  46.571\\
40  45.09\\
45  44.637\\
50  43.57\\
};
\addlegendentry{MVTRAD output power 1st}

\addplot [color=mycolor4, line width=1.0pt, draw=none, mark size=3.0pt, mark=diamond, mark options={solid, red}]
  table[row sep=crcr]{%
5   40.67\\
10  39.74\\
15  39.71\\
20  36.96\\
25  37.54\\
30  37.12\\
35  36.99\\
40  39.74\\
45  40.71\\
50  37.87\\
};
\addlegendentry{IM power left}

\addplot [color=mycolor5, line width=1.0pt, draw=none, mark size=3.0pt, mark=x, mark options={solid, blue}]
  table[row sep=crcr]{%
5   37.3\\
10  37.46\\
15  37.47\\
20  37.49\\
25  37.43\\
30  37.51\\
35  37.38\\
40  37.45\\
45  37.47\\
50  37.61\\
};
\addlegendentry{IMAL IM power left}

\addplot [color=mycolor6, line width=1.0pt, draw=none, mark size=3.0pt, mark=asterisk, mark options={solid, black}]
  table[row sep=crcr]{%
5   12.903\\
10  22.986\\
15  29.028\\
20  33.666\\
25  36.422\\
30  37.281\\
35  37.006\\
40  36.143\\
45  34.935\\
50  33.81\\
};
\addlegendentry{MVTRAD IM power left}

\end{axis}
\end{tikzpicture}%

enter image description here

3

I guess this is a problem in matlab2tikz.

The easiest way to get what you want is to add the option only marks to the legend style, i.e. change the line

legend style={at={(0.5,-0.2)}, anchor=north, legend columns=2, legend cell align=left, align=left, draw=white!15!black}

to

legend style={only marks, at={(0.5,-0.2)}, anchor=north, legend columns=2, legend cell align=left, align=left, draw=white!15!black}

Matlab2tikz seem to remove the plot lines with the option draw=none. If the option only marks is used instead of draw=none in every \addplot [...], the legend looks as it should.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy