使用 TikZ 创建两个图形的堆

使用 TikZ 创建两个图形的堆

为了写一份学校课程报告,我需要根据输入对某个电路的输出信号进行分析。这是我试图重现的图表:

施密特触发器

它由两张堆叠在一起的图表组成,一张叠在另一张上面。我实际上查阅了texample.net以便自己尝试,但我完全做不到。我创建了两个{tikzpicture}块来实现它,但在从输入一直到输出绘制红色虚线垂直线时,我失败了。我看了这两个例子:

答案1

y=2这是一个提议,它从上图与和线的交点得出下图y=-2

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}% <- if you have an older installation, try 1.15 or 1.14
\usepgfplotslibrary{groupplots,fillbetween}
\begin{document}
\begin{tikzpicture}[node font=\sffamily]
   \begin{groupplot}[group style={group size=1 by 2,vertical sep=4.5em},
       width=9cm,height=5cm,
       xmin=0,xmax=0.035,ymin=-5.2,ymax=5.2,
       xtick={0,0.005,...,0.035},grid=major,
       domain=0:0.035,xlabel={},axis on top,samples=201,
       scaled x ticks=false,/pgf/number format/fixed,
       x tick label style={font=\small},y tick label style={font=\small}]
    \nextgroupplot[title={Input signal},
        ylabel={Input signal voltage},ytick={-5,-2,2,5}]
      \addplot[smooth, cyan,thick,name path=sine] {5*sin((x/0.035)*730)};
      \path[name path=upper] (\pgfkeysvalueof{/pgfplots/xmin},2)
        -- (\pgfkeysvalueof{/pgfplots/xmax},2);
      \path[name path=lower] (\pgfkeysvalueof{/pgfplots/xmin},-2)
        -- (\pgfkeysvalueof{/pgfplots/xmax},-2);
      \path[name intersections={of={sine and upper},name=u},
        name intersections={of={sine and lower},name=l}];
      \path (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax})
        coordinate (TR1);       
    \nextgroupplot[title={Schmitt output signal},
        ytick={-5,-3,3,5},ylabel={Schmitt trigger voltage output}]
       \draw[cyan,thick] (0,-3) -| (u-1|-0,3) coordinate (U-1) 
        -| (l-1|-0,-3) coordinate (L-1) -| (u-3|-0,3) coordinate (U-3)
       -| (l-3|-0,-3) coordinate (L-3)-- (0.035,-3);
      \path (\pgfkeysvalueof{/pgfplots/xmax},\pgfkeysvalueof{/pgfplots/ymax})
        coordinate (TR2);       
   \end{groupplot}
   \draw[red,dashed] foreach \X in {1,3} {(u-\X) -- (U-\X)};
   \draw[dashed] foreach \X in {1,3} {(l-\X) -- (L-\X)};
    \path foreach \X in {1,2} 
    {(TR\X) node[anchor=north east,align=right,font=\small]     
    {$V_\mathrm{OL} = 3\mathrm{V}$\\
    $V_\mathrm{HL} = 3\mathrm{V}$}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容