到目前为止,这就是我出色的作品。看起来不错,但现在我奇迹般地发现有时我需要负 y 轴。然而,简单地将 ymin 和 ymax 添加到有问题的 U_L 图的 \begin{axis} 并不能解决问题。
该怎么办?
谢谢。
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{decorations, arrows}
\usepackage{amsmath}
\pgfplotsset{Diagram/.style={
axis lines = left,
xmax=9,
xmin=0,
ymax=1.5,
ymin=0,
xlabel = {$t$},
xlabel style={at={(1,0)},anchor=west},
ylabel style={at={(0,1)},rotate={-90},anchor=north east},
ytick=\empty,
no marks,
every axis plot post/.append style={very thick, red},
}% end of Diagram style
}% end of pgfplotsset
\begin{document}
%%%%%%%%%%%% Diagramme f. 4TPPC %%%%%%%%%%%%
\begin{figure}
\pgfplotsset{xticklabels={ , , , $T/2$, , $T$}, height=4cm, width=0.8\textwidth}
\centering
\begin{tikzpicture}[trim axis left]
\begin{axis}[Diagram, ylabel = $U_{GS_{1,4}}$, extra x ticks={3,7}, extra x tick labels={\mbox{\tiny $DT$},\mbox{\tiny ${T/2+DT}$}}]
\addplot coordinates {(0,1) (3,1) (3,0) (8,0) };
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[trim axis left]
\begin{axis}[Diagram, ylabel = $U_{GS_{2,3}}$, extra x ticks={3,7}, extra x tick labels={\mbox{\tiny $DT$},\mbox{\tiny ${T/2+DT}$}}]
\addplot coordinates {(0,0) (4,0) (4,1) (7,1) (7,0) (8,0)};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[trim axis left]
\begin{axis}[Diagram, ylabel = $U_L$, extra x ticks={3,7}, extra x tick labels={\mbox{\tiny $DT$},\mbox{\tiny ${T/2+DT}$}}, ymin=-2, ymax=2]
\addplot coordinates {(0,.5) (3,.5) (3,-1.5) (8,-1.5) };
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[trim axis left]
\begin{axis}[Diagram, ylabel = $i_L$, extra x ticks={3,7}, extra x tick labels={\mbox{\tiny $DT$},\mbox{\tiny ${T/2+DT}$}}]
\addplot coordinates {(0,.4) (3,.7) (4,.4) (7,.7) (8,.4) };
\draw [ultra thin, blue, dashed] (0,0.7) -- (8,0.7) ;
\draw [ultra thin, blue, dashed] (0,.4) -- (8,0.4) ;
\draw [thick, blue, <->] (8,.4) -- (8,.7);
\node [right] at (8,.55){$\Delta i_L$};
\end{axis}
\end{tikzpicture}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\end{document}
答案1
- 在我的答案我预料到您的图表只会在第一象限,但扩展提出的解决方案非常简单。相反,
pgfplots
使用以下内容定义通用样式(图表):
\pgfplotsset{Diagram/.style={
axis lines = middle,
xmax=9,
% xmin=0, % <--- removed
ymax=1.5,
ymin=0,
xlabel = {$t$},
xlabel style={anchor=west}, % <--- changed
xticklabel style={font=\scriptsize}, % <--- added
% ylabel style={at={(0,1)}}, % <--- removed
ytick=\empty,
no marks,
every axis plot post/.append style={very thick, red},
}% end of Diagram style
}% end of pgfplotsset
- 您始终可以使用 new 在本地覆盖全局(通用)设置。它仅在 used或as is done in 中
\pgfplotssset
有效tikzzpicture
figure
姆韦以下 - 如果一个图中的图表具有共同的附加样式,则在本地定义它是明智的(对于较短的代码),
pgfplotsset
就像在姆韦以下 - 对于刻度标签,您的解决方案最好以通用
pgfplots
样式定义字体大小
像这样?
\documentclass[11pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\pgfplotsset{Diagram/.style={
axis lines = middle,
xmax=9,
% xmin=0, % <--- removed
ymax=1.5,
ymin=0,
xlabel = {$t$},
xlabel style={anchor=west}, % <--- changed
xticklabel style={font=\scriptsize}, % <--- added
% ylabel style={at={(0,1)}}, % <--- removed
ytick=\empty,
no marks,
every axis plot post/.append style={very thick, red},
}% end of Diagram style
}% end of pgfplotsset
\begin{document}
%%%%%%%%%%%% Diagramme f. 4TPPC %%%%%%%%%%%%
\begin{figure}
\pgfplotsset{xticklabels={ , , , $T/2$, , $T$},
height=4cm, width=0.8\textwidth,
extra x ticks={3,7},
extra x tick labels={$DT$,${T/2+DT}$}
}
\centering
\begin{tikzpicture}
\begin{axis}[Diagram, ylabel = $U_{GS_{1,4}}$]
\addplot coordinates {(-1,1) (3,1) (3,0) (8,0) };
\end{axis}
\end{tikzpicture}
\medskip
\begin{tikzpicture}
\begin{axis}[Diagram, ylabel = $U_{GS_{2,3}}$]
\addplot coordinates {(-1,0) (4,0) (4,1) (7,1) (7,0) (8,0)};
\end{axis}
\end{tikzpicture}
\medskip
\begin{tikzpicture}
\begin{axis}[Diagram,
ymin=-1.5, % <---- added
ylabel = $U_L$]
\addplot coordinates {(-1,.5) (0,.5) (3,.5) (3,-1.5) (8,-1.5) };
\end{axis}
\end{tikzpicture}
\medskip
\begin{tikzpicture}
\begin{axis}[Diagram,
xmin=-1, % <---- added
ylabel = $i_L$, ]
\addplot coordinates {(0,.4) (3,.7) (4,.4) (7,.7) (8,.4) };
\draw [ultra thin, blue, dashed] (0,0.7) -- (8,0.7) ;
\draw [ultra thin, blue, dashed] (0,.4) -- (8,0.4) ;
\draw [thick, blue, <->] (8,.4) -- (8,.7);
\node [right] at (8,.55){$\Delta i_L$};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
编辑:
在某些情况下,你有如下所示的混合图,一些带有负独立变量,一些只有正独立变量,并且在这种混合图中,图的坐标轴对齐并不重要,你可以删除xmin=-1
在最后一个图中删除,然后获得以下结果:
最后一张图的代码是:
...
\begin{tikzpicture}
\begin{axis}[Diagram,
ylabel = $i_L$, ]
\addplot coordinates {(0,.4) (3,.7) (4,.4) (7,.7) (8,.4) };
\draw [ultra thin, blue, dashed] (0,0.7) -- (8,0.7) ;
\draw [ultra thin, blue, dashed] (0,.4) -- (8,0.4) ;
\draw [thick, blue, <->] (8,.4) -- (8,.7);
\node [right] at (8,.55){$\Delta i_L$};
\end{axis}
\end{tikzpicture}
...