생략/결측값이 있는 이산형 그래프 플롯

생략/결측값이 있는 이산형 그래프 플롯

나는 거기처럼 그래프를 그리고 싶다(이산 신호 플로팅) 그러나 값에 점이 있으면 "정보 없음"(...)과 같이 y 값이 없는 x의 점선 값을 의미합니다. 이 스레드의 코드를 약간 변경했지만 "점"을 추가하는 데 어려움을 겪고 있습니다. 아래에는 내가 원하는 예제와 출력이 있는 tex 코드를 첨부합니다. 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}

이것이 제가 음모를 꾸미고 싶은 것입니다. 여기에 이미지 설명을 입력하세요

텍스 출력입니다. 여기에 이미지 설명을 입력하세요

이것은 내가 플롯하려는 내용을 설명하는 출력에 대한 내 그림입니다. 여기에 이미지 설명을 입력하세요

읽어 주셔서 감사합니다.

답변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}

여기에 이미지 설명을 입력하세요

관련 정보