如何使用 pgfplots 在两个单独的图之间添加空间?

如何使用 pgfplots 在两个单独的图之间添加空间?

我目前有以下情况:

地块

现在你可能可以想象我并不想这样。我希望右上图与右下图对齐。但是当我使用 at 和 anchor 语句执行此操作时,图会略微下降,不再与左上图对齐。我的问题是如何解决这个问题?明确地说,我希望右上图与左上图和右下图对齐。

我有以下代码,请注意我从图中删除了数据,因为它有很多点。

\documentclass[a4paper,11pt,twoside]{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.7]

\begin{semilogxaxis}[%
view={0}{90},
width=10cm,
height=5cm,
scale only axis,
every outer x axis line/.append style={gray!80!black},
every x tick label/.append style={font=\color{gray!80!black}},
xmin=0.1, xmax=1000,
xlabel={Frequency (rad/s)},
xminorticks=true,
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={gray!80!black},
every y tick label/.append style={font=\color{gray!80!black}},
ymin=-200, ymax=200,
ylabel={Phase (deg)},
ymajorgrids,
name=plot1]

\addplot [
color=blue,
solid,
line width=1.5pt,
forget plot
]
coordinates{
 (0,0)
};

\end{semilogxaxis}

\begin{semilogxaxis}[%
view={0}{90},
width=10cm,
height=5cm,
scale only axis,
every outer x axis line/.append style={gray!80!black},
every x tick label/.append style={font=\color{gray!80!black}},
xmin=0.1, xmax=1000,
xticklabels={\empty}
xminorticks=true,
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={gray!80!black},
every y tick label/.append style={font=\color{gray!80!black}},
ymin=-350, ymax=50,
ylabel={Magnitude (dB)},
ymajorgrids,
at=(plot1.above north west), 
anchor=below south west,
name=plot2]

\addplot [
color=blue,
solid,
line width=1.5pt,
forget plot
]
coordinates{
 (0,-76.9482975559457)
};

\end{semilogxaxis}

\begin{semilogxaxis}[%
view={0}{90},
width=10cm,
height=5cm,
scale only axis,
every outer x axis line/.append style={gray!80!black},
every x tick label/.append style={font=\color{gray!80!black}},
xmin=0.1, xmax=1000,
xlabel={Frequency (rad/s)},
xminorticks=true,
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={gray!80!black},
every y tick label/.append style={font=\color{gray!80!black}},
ymin=-200, ymax=200,
yticklabels={\empty},
ymajorgrids,
at=(plot1.right of south east), 
anchor=left of south west,
name=plot3]

\addplot [
color=blue,
solid,
line width=1.5pt,
forget plot
]
coordinates{
 (0,0)
};

\end{semilogxaxis}

\begin{semilogxaxis}[%
view={0}{90},
width=10cm,
height=5cm,
scale only axis,
every outer x axis line/.append style={gray!80!black},
every x tick label/.append style={font=\color{gray!80!black}},
xmin=0.1, xmax=1000,
xticklabels={\empty}
xminorticks=true,
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={gray!80!black},
every y tick label/.append style={font=\color{gray!80!black}},
yticklabels={\empty},
ymin=-350, ymax=50,
ymajorgrids,
at={(plot2.right of south east)}, 
anchor={left of south west},
name=plot4]

\addplot [
color=blue,
solid,
line width=1.5pt,
forget plot
]
coordinates{
 (0,-47.4053700922616)
};

\end{semilogxaxis}
\end{tikzpicture}
\end{document}

答案1

这些没有按预期对齐的原因是第二张图没有 x 轴标签。这可以通过设置标签的宽度来实现:

\pgfplotsset{xticklabel style={text width=2em,align=right}}

得出的结果是:

在此处输入图片描述

参考:

代码:

\documentclass[a4paper,11pt,twoside]{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.7]

\pgfplotsset{xticklabel style={text width=2em,align=right}}% <--- Added

\begin{semilogxaxis}[%
view={0}{90},
width=10cm,
height=5cm,
scale only axis,
every outer x axis line/.append style={gray!80!black},
every x tick label/.append style={font=\color{gray!80!black}},
xmin=0.1, xmax=1000,
xlabel={Frequency (rad/s)},
xminorticks=true,
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={gray!80!black},
every y tick label/.append style={font=\color{gray!80!black}},
ymin=-200, ymax=200,
ylabel={Phase (deg)},
ymajorgrids,
name=plot1]

\addplot [
color=blue,
solid,
line width=1.5pt,
forget plot
]
coordinates{
 (0,0)
};

\end{semilogxaxis}

\begin{semilogxaxis}[%
view={0}{90},
width=10cm,
height=5cm,
scale only axis,
every outer x axis line/.append style={gray!80!black},
every x tick label/.append style={font=\color{gray!80!black}},
xmin=0.1, xmax=1000,
xticklabels={\empty}
xminorticks=true,
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={gray!80!black},
every y tick label/.append style={font=\color{gray!80!black}},
ymin=-350, ymax=50,
ylabel={Magnitude (dB)},
ymajorgrids,
at=(plot1.above north west), 
anchor=below south west,
name=plot2]

\addplot [
color=blue,
solid,
line width=1.5pt,
forget plot
]
coordinates{
 (0,-76.9482975559457)
};

\end{semilogxaxis}

\begin{semilogxaxis}[%
view={0}{90},
width=10cm,
height=5cm,
scale only axis,
every outer x axis line/.append style={gray!80!black},
every x tick label/.append style={font=\color{gray!80!black}},
xmin=0.1, xmax=1000,
xlabel={Frequency (rad/s)},
xminorticks=true,
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={gray!80!black},
every y tick label/.append style={font=\color{gray!80!black}},
ymin=-200, ymax=200,
yticklabels={\empty},
ymajorgrids,
at=(plot1.right of south east), 
anchor=left of south west,
name=plot3]

\addplot [
color=blue,
solid,
line width=1.5pt,
forget plot
]
coordinates{
 (0,0)
};

\end{semilogxaxis}

\begin{semilogxaxis}[%
view={0}{90},
width=10cm,
height=5cm,
scale only axis,
every outer x axis line/.append style={gray!80!black},
every x tick label/.append style={font=\color{gray!80!black}},
xmin=0.1, xmax=1000,
xticklabels={\empty}
xminorticks=true,
xmajorgrids,
xminorgrids,
every outer y axis line/.append style={gray!80!black},
every y tick label/.append style={font=\color{gray!80!black}},
yticklabels={\empty},
ymin=-350, ymax=50,
ymajorgrids,
at={(plot2.right of south east)}, 
anchor={left of south west},
name=plot4]

\addplot [
color=blue,
solid,
line width=1.5pt,
forget plot
]
coordinates{
 (0,-47.4053700922616)
};

\end{semilogxaxis}
\end{tikzpicture}
\end{document}

相关内容