省略された/欠損値を含む離散グラフをプロットする

省略された/欠損値を含む離散グラフをプロットする

次のようなグラフをプロットしたい(離散信号のプロット) ですが、値にドットがあります。つまり、x にドットがあり、y の値がない場合は、「情報なし」のようになります (...)。 このスレッドからコードを少し変更しましたが、「ドット」の追加に苦労しています。 以下に、必要な例と、その出力を含む TEX コードを添付します。 Google で 1 時間検索しましたが、結果は得られませんでした。

テックスコード

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage{pgfplots}
\title{}
\author{}
\date{}

\begin{document}



\begin{filecontents}{data.dat}
 n   xn 
 0    10  
 1    9  
 2    5  
 3    2  
 4    -3
 5 -
 20    8
 21 3
\end{filecontents}


\begin{tikzpicture}
\begin{axis}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    scale=1.3,
    axis x line=middle,
    axis y line=middle,
    every axis x label={at={(current axis.right of origin)},anchor=north west},
    every axis y label={at={(current axis.above origin)},anchor= north west},
    every axis plot post/.style={mark options={fill=black}},   
    xmin=0,
    xmax=20, 
    xtick={0,1, 2, 3,4,5,20, 21},    
    xticklabels={0,1, 2, 3, 4, .., 20, 21},
    xlabel={$\boldsymbol{x}$},
    ylabel={$\boldsymbol{z[n]}$},
    ytick={-5, 10},   
    ymin=-5,
    ymax=10,
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\addplot+[ycomb,black, very thick] table [x={n}, y={xn}] {data.dat};
\end{axis}
\end{tikzpicture}



\end{document}

これが私が計画したいものです。 ここに画像の説明を入力してください

これはTEX出力です。 ここに画像の説明を入力してください

これは私がプロットしたいものを説明した出力の図のようなものです。 ここに画像の説明を入力してください

読んでくれてありがとう。

答え1

追加するのはどうでしょうか

\path[draw,loosely dotted,thick,black](6,-1)--(19,-1);

軸環境内では?

答え2

問題を解決する方法は、@ukg の回答 (+1) に示されています。ここでは、MWE をどのように改善できるかについてのトピック提案をいくつか示します (私の意見による)。

\RequirePackage{filecontents}
    \begin{filecontents}{data.dat}
 n    xn
 0    10
 1     9
 2     5
 3     2
 4    -3
12    -3
13     2
14     5
20     8
21     3
25   nan
    \end{filecontents}

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[x=4mm,
    axis lines=middle,
    axis on top,
    xlabel=$x$,         
    ylabel=${z[n]}$,    
    label style={anchor=north east},
    xtick=data,
    tick label style = {fill=white, inner sep=2pt, font=\scriptsize}, 
    extra x ticks = {0},
    ymin=-5, ymax=10,
    enlarge x limits={0.1},
    enlarge y limits={0.2,upper},
    every axis plot post/.style={very thick},
            ]
\addplot [ycomb, mark=*] table [x=n, y=xn] {zdata.dat};
\draw[very thick, dash pattern=on 1pt off 3pt, 
      transform canvas={yshift=-1.5ex}
      ]    
        (6,0) -- (10,0)     % 6: position of 6th tick, 
                            % 10: position od 10th tick
        (16,0) -- (18,0);
\end{axis}
    \end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報