matlab2tikz:图例与 x 标签重叠

matlab2tikz:图例与 x 标签重叠

我创建了一个 Matlab 图形,并使用 matlab2tikz 脚本将其转换为 tikz。我在图形外绘制了一个图例。不幸的是,这个图例与我的 x 轴标签重叠。有人能告诉我如何改变这种情况吗?

这是 tikz 文件:

% 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}%

以下是我将其包含到我的文档中的方式:

\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

at图例的位置由中的键决定legend style。查看环境选项列表axis,你会发现以下内容:

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

将 y 坐标更改为-0.1,图例位于 xticklabels 下方。

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

您可能还对此感兴趣legend columns=2。将其添加到以legend style使图例条目分布在两列上。

相关内容