x 轴有断点的茎状图

x 轴有断点的茎状图

我正在尝试绘制一个茎状图,其中有一些值靠近原点,一组值远离原点。我已经看过这个答案。这是我的尝试:

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[scale=1]

\begin{groupplot}[
  group style={
    group name=my fancy plots,
    group size=2 by 1,
    %xticklabels at=edge bottom,
    horizontal sep=0pt
 },
 ymin=0, ymax=1.5
  ]
  \nextgroupplot[ymin=0, ymax=1.5,
    axis lines=middle, xtick={-1,...,1},
    xticklabels={-1,...,1},
    enlarge x limits=0.5,
    enlarge y limits=0.5,
    extra x tick style={
      xticklabel style={yshift=0.5ex, anchor=south}},
      xmin=-1.5,xmax=1.5, ytick={\empty}, yticklabels={}, 
      axis on top,
      axis line style={-Latex[round]},
      ]
    \addplot+[ycomb,black,very thick] plot coordinates
      {(-1,0) (0,1) (1,0)};
    \node[anchor=east] at (axis cs:0,1.5) {$x[n]$};

 \nextgroupplot[xmin=999, xmax=1001,
 axis lines=middle,
 hide y axis,
 ymin=0, ymax=1.5,
 xtick=1000,
 xticklabels=1000,
 axis x discontinuity=crunch,
 ]
 \addplot+[ycomb,black,very thick] plot coordinates
 {(999,0) (1000,1) (1001,0)};
 \node[anchor=south] at (axis cs:1000,1) {$1$};
 \node[anchor=north] at (axis cs:1001.5,0) {$n$};

 \end{groupplot}
 \end{tikzpicture}%
 \end{document}

我得到的结果是不完全对齐的,至少可以这么说。我所寻找的是轴对齐,第一个图轴没有 x 轴箭头,两个 x 轴用波浪线连接(以显示不连续性),高度正确缩放以匹配。点之间的间距(在 n = -1、0 和 1 处与在 n = 999、1000 和 1001 处的点)也不同,但我要求它们等距。由于我一直在学习、忘记和重新学习,请原谅我幼稚的 MWE 代码。

在此处输入图片描述

答案1

正如 Ulrike 指出的那样,您需要调整第二个图的 y 限制。去掉箭头很简单,只需添加

every inner x axis line/.append style={-},

axis line stylee={-Latex[round]}

\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{pgfplots.groupplots}
\usetikzlibrary{arrows.meta}

\begin{document}
\begin{tikzpicture}[scale=1]

\begin{groupplot}[
  group style={
    group name=my fancy plots,
    group size=2 by 1,
    %xticklabels at=edge bottom,
    horizontal sep=0pt
 },
 ymin=0, ymax=1.5
  ]
  \nextgroupplot[ymin=0, ymax=1.5,
    axis lines=middle, xtick={-1,...,1},
    xticklabels={-1,...,1},
    enlarge x limits=0.5,
    enlarge y limits=0.5,
    extra x tick style={
      xticklabel style={yshift=0.5ex, anchor=south}},
    xmin=-1.5,xmax=1.5, ytick={\empty}, yticklabels={}, 
    axis on top,
    axis line style={-Latex[round]},
    every inner x axis line/.append style={-},
      ]
    \addplot+[ycomb,black,very thick] plot coordinates
      {(-1,0) (0,1) (1,0)};
    \node[anchor=east] at (axis cs:0,1.5) {$x[n]$};

 \nextgroupplot[xmin=999, xmax=1001,
 axis lines=middle,
 hide y axis,
 ymin=-0.5, ymax=1.5,
 xtick=1000,
 xticklabels=1000,
 axis x discontinuity=crunch,
 ]
 \addplot+[ycomb,black,very thick] plot coordinates
 {(999,0) (1000,1) (1001,0)};
 \node[anchor=south] at (axis cs:1000,1) {$1$};
 \node[anchor=north] at (axis cs:1001.5,0) {$n$};
 \end{groupplot}
 \end{tikzpicture}%
 \end{document}

在此处输入图片描述

相关内容