tikz 中的轴对齐

tikz 中的轴对齐

您好,我在 TikZ 中 y 轴对齐方面遇到了问题!最后一个图的 y 轴与其他两个图不对齐!修剪左轴不起作用!有人能帮我吗?谢谢!

\documentclass[svgnames,a4paper,ngerman,fontsize=12pt]{scrreprt}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{pgfplots}

\begin{document}
\begin{figure}[!h]\centering

\begin{tikzpicture}[xscale=8,yscale=5]
\draw [->, thick] (0,0) -- (0,0.5)node[left]{$U,I$};
\draw [->, thick] (0,0) -- (1.1,0)node[below]{$t$}; 
\draw [blue, ultra thick, rounded corners] (0,0.3)--(0.1,0.3)--(0.15,0.22)--(0.2,0.22)--(0.22,0.02)--(0.8,0.02)--(0.85,0.4)--(0.88,0.3)--(1,0.3)node[above,blue]{$u(t)$};
\draw [red, ultra thick, rounded corners] (0,0)--(0.1,0)--(0.18,0.4)--(0.2,0.3)--(0.83,0.3)--(0.85,0.0)--(1,0.0)node[above,red]{$i(t)$};
\end{tikzpicture}

\begin{tikzpicture}[xscale=8,yscale=5]
\draw [->, thick] (0,0) -- (0,0.5)node[left]{$P$};
\draw [->, thick] (0,0) -- (1.1,0)node[below]{$t$}; 
\draw [orange, ultra thick, rounded corners] (0,0)--(0.1,0)--(0.15,0.4)--(0.22,0.05)--(0.8,0.05)--(0.85,0.3)--(0.9,0.0)--(1.0,0.0);
 \end{tikzpicture}
\begin{tikzpicture}[xscale=8,yscale=5]
\draw [->, thick] (0,0) -- (0,0.5)node[left]{$E$};
\draw [->, thick] (0,0) -- (1.1,0)node[below]{$t$}; 
\draw[purple, ultra thick, rounded corners]
(0,0)--(0.1,0)--(0.2,0.2)--(0.8,0.3)--(0.9,0.4)--(1,0.4);
\draw[thick](0.1,-0.01)--(0.1,0.01);
\draw[thick](0.2,-0.01)--(0.2,0.01);
\draw (0.15,0)node[below]{$E_{on}$};
\draw[thick](0.8,-0.01)--(0.8,0.01);
\draw[thick](0.9,-0.01)--(0.9,0.01);
\draw (0.85,0)node[below]{$E_{off}$};
\draw[decorate,thick,decoration={brace, mirror}] (0.2,-0.01)--node[below]{xxx}(0.8,-0.01) ; 
\end{tikzpicture}
\caption{Plot}\label{fig:PvIGBT}
\end{figure}
\end{document}

答案1

错位是由 x 轴下方的标签引起的,这导致最后一个图形的边界框比前两个图形更大。

您可以手动指定每个图形的边界框,为三个图形提供相同的边界框,使用 bb 的尺寸作为轴的尺寸。这意味着向每个 tikzpicture 添加以下行:

\path[use as bounding box] (0,0) rectangle (1.1, 0.5);

结果:

结果

但请注意,边界框之外的所有内容“不是图形的一部分”,尽管它仍然显示出来,因此它可以与周围的文本重叠。在这种情况下,这种效果几乎不可察觉(图形的标题将更靠近图的 x 轴)。

答案2

如果您使用pgfplot通常的方法,则可以调整标签的样式,如下所示:

由于您使用的tikz上述解决方案在这种特定情况下不起作用,但是您可以使用来模拟\makebox[][]{}以确保所有标签都占据相同的空间。因此,下面我定义了一个\FormatLabel宏来确保所有标签都占据3em水平空间:

在此处输入图片描述

代码:

\documentclass[svgnames,a4paper,ngerman,fontsize=12pt]{scrreprt}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usepackage{pgfplots}

% Equivalent of the following \pgfplotsset set is \FormatLabel
%\pgfplotsset{yticklabel style={text width=3em,align=right}}
\newcommand*{\FormatLabel}[1]{\makebox[3em][r]{#1}}%

\begin{document}
\begin{figure}[!h]\centering

\begin{tikzpicture}[xscale=8,yscale=5]
\draw [->, thick] (0,0) -- (0,0.5)node[left]{\FormatLabel{$U,I$}};
\draw [->, thick] (0,0) -- (1.1,0)node[below]{$t$}; 
\draw [blue, ultra thick, rounded corners] (0,0.3)--(0.1,0.3)--(0.15,0.22)--(0.2,0.22)--(0.22,0.02)--(0.8,0.02)--(0.85,0.4)--(0.88,0.3)--(1,0.3)node[above,blue]{$u(t)$};
\draw [red, ultra thick, rounded corners] (0,0)--(0.1,0)--(0.18,0.4)--(0.2,0.3)--(0.83,0.3)--(0.85,0.0)--(1,0.0)node[above,red]{$i(t)$};
\end{tikzpicture}

\begin{tikzpicture}[xscale=8,yscale=5]
\draw [->, thick] (0,0) -- (0,0.5)node[left]{\FormatLabel{$P$}};
\draw [->, thick] (0,0) -- (1.1,0)node[below]{$t$}; 
\draw [orange, ultra thick, rounded corners] (0,0)--(0.1,0)--(0.15,0.4)--(0.22,0.05)--(0.8,0.05)--(0.85,0.3)--(0.9,0.0)--(1.0,0.0);
 \end{tikzpicture}
\begin{tikzpicture}[xscale=8,yscale=5]
\draw [->, thick] (0,0) -- (0,0.5)node[left]{\FormatLabel{$E$}};
\draw [->, thick] (0,0) -- (1.1,0)node[below]{$t$}; 
\draw[purple, ultra thick, rounded corners]
(0,0)--(0.1,0)--(0.2,0.2)--(0.8,0.3)--(0.9,0.4)--(1,0.4);
\draw[thick](0.1,-0.01)--(0.1,0.01);
\draw[thick](0.2,-0.01)--(0.2,0.01);
\draw (0.15,0)node[below]{$E_{on}$};
\draw[thick](0.8,-0.01)--(0.8,0.01);
\draw[thick](0.9,-0.01)--(0.9,0.01);
\draw (0.85,0)node[below]{$E_{off}$};
\draw[decorate,thick,decoration={brace, mirror}] (0.2,-0.01)--node[below]{xxx}(0.8,-0.01) ; 
\end{tikzpicture}
\caption{Plot}\label{fig:PvIGBT}
\end{figure}
\end{document}

相关内容