1

I have created a Matlab figure and converted it to tikz using the matlab2tikz script. I plot a legend outside of my figure. Unfortunately this legend overlaps with my x-axis label. Can anybody tell me how to change this?

here is the tikz-file:

% 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.00000,1.00000,1.00000}%
\definecolor{mycolor7}{rgb}{0.30100,0.74500,0.93300}%
\definecolor{mycolor8}{rgb}{1.00000,0.00000,1.00000}%
\definecolor{mycolor9}{rgb}{0.63500,0.07800,0.18400}%
\definecolor{mycolor10}{rgb}{1.00000,1.00000,0.00000}%
%
\begin{tikzpicture}

\begin{axis}[%
width=4.602in,
height=2.329in,
at={(0.772in,1.853in)},
scale only axis,
xmin=0,
xmax=55,
xtick={5,10,15,20,25,30,35,40,45,50},
xticklabels={{case1},{case2},{case3},{case4},{case5},{case6},{case7},{case8},{case9},{case10}},
ymin=0,
ymax=60,
axis background/.style={fill=white},
axis x line*=bottom,
axis y line*=left,
xmajorgrids,
ymajorgrids,
legend style={at={(0.5,-0.03)}, anchor=north, legend cell align=left, align=left, draw=white!15!black}
]
\addplot [color=mycolor1, line width=2.0pt, draw=none, mark size=3.5pt, 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 [dBm]}

\addplot [color=mycolor2, line width=2.0pt, draw=none, mark size=3.5pt, mark=square, mark options={solid, blue}]
  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 1st [dBm]}

\addplot [color=mycolor3, line width=2.0pt, draw=none, mark size=3.5pt, mark=square, mark options={solid, green}]
  table[row sep=crcr]{%
5   9.58\\
10  9.36\\
15  9.7\\
20  11.03\\
25  10.54\\
30  10.76\\
35  10.74\\
40  9.29\\
45  9.39\\
50  13.18\\
};
\addlegendentry{D3 1st}

\addplot [color=mycolor4, line width=2.0pt, draw=none, mark size=3.5pt, mark=square, mark options={solid, black}]
  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 [dBm]}

\addplot [color=mycolor5, line width=2.0pt, draw=none, mark size=3.5pt, mark=square, mark options={solid, mycolor6}]
  table[row sep=crcr]{%
5   37.3\\
10  37.46\\
15  37.47\\
20  37.49\\
25  37.43\\
30  37.4\\
35  37.53\\
40  37.47\\
45  37.44\\
50  37.33\\
};
\addlegendentry{IMAL IM power 1st [dBm]}

\addplot [color=mycolor7, line width=2.0pt, draw=none, mark size=3.5pt, mark=square, mark options={solid, mycolor8}]
  table[row sep=crcr]{%
5   10.72\\
10  10.55\\
15  10.53\\
20  10.45\\
25  10.59\\
30  10.56\\
35  10.5\\
40  10.54\\
45  10.55\\
50  10.63\\
};
\addlegendentry{IMAL D3 1st}

\addplot [color=mycolor9, line width=2.0pt, draw=none, mark size=3.5pt, mark=square, mark options={solid, mycolor10}]
  table[row sep=crcr]{%
5   29.044\\
10  21.282\\
15  17.056\\
20  13.719\\
25  11.614\\
30  10.059\\
35  9.953\\
40  10.177\\
45  10.092\\
50  11.211\\
};
\addlegendentry{D3 measuremens}

\end{axis}
\end{tikzpicture}%

and here is how I have included it into my document:

\documentclass[11pt,a4paper, oneside]{article}
\usepackage[utf8]{inputenc}
\usepackage[ngerman,english]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[free-standing-units]{siunitx}

\DeclareSIUnit{\belmilliwatt}{Bm}
\DeclareSIUnit{\dBm}{\deci\belmilliwatt}

\usepackage{listings}
\lstset{basicstyle=\footnotesize, keywordstyle=\color{blue}}

\usepackage{gensymb}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{color}
\usepackage[format=hang]{caption}
\usepackage{placeins}              

%TikZ package
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usetikzlibrary{plotmarks}

\begin{document}

\begin{figure}[h]
\centering
\input{IMAL_vs_PSB1st}
\caption{IMAL vs PSB 1st}
\label{IMAL_vs_PSB1st}
\end{figure}

\end{document}

1 Answer 1

0

The position of the legend is determined by the at key in the legend style. Look in the list of options for the axis environment, and you'll find this:

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

Change the y-coordinate to -0.1 and the legend is below the xticklabels.

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

You might also be interested in legend columns=2. Add that to the legend style to get the legend entries distributed over two columns.

0

You must log in to answer this question.