1

I am trying to get a stem plot in which there are a few values near the origin and a group of values far away. I have already looked at this answer. Here is my attempt:

\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}

What I am getting is not quite aligned, to say the least. What I am looking for is for the axes to be aligned, no x-axis arrowhead for the first plots axis, joining of the two x-axes with that wavy line (to show the discontinuity) and the heights scaled correctly to match. The spacing between the dots (at n = -1, 0, and 1 versus those at n = 999, 1000, and 1001) is also different but I require them to be equispaced. Since I keep learning, forgetting and relearning, please excuse the naive MWE code.

enter image description here

Stefan Pinnow
  • 29,535
CSR
  • 175
  • 2
    you are enlarging the y limits in the one plot but not the other. Btw: the minimal class is often too minimal for an example, better use article. – Ulrike Fischer Feb 08 '20 at 11:48
  • Thanks. I am able to now align the axes. If I can get rid of the arrowhead on the x-axis of the first plot, I'd be done, I think. BTW, I now duplicated the first plot and merely changed the x-axis labels to what I want (i.e., 999, 1000, 1001). The spacing of these points and the y-axis scaling is now what I want. Is this the correct way to do it? – CSR Feb 08 '20 at 11:54

1 Answers1

3

As Ulrike pointed out, you need to adjust the y limits of the second plot. Getting rid of the arrow head is as simple as adding

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

after 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}

enter image description here