My question is closely related to this one, which has not been answered yet and might get more attention in this more general formulation.

Suppose that a bunch of (abscissa, ordinate) points contains missing or infinite values which can be flagged somehow, for instance by directly having nan in the ordinate as I assume below, or by testing out-of-bounds values as in the above mentioned question. Is there a simple modification of \listplot which would plot a different curve for each group of contiguous values without missing/infinite value ?

Below is an illustration. First, I plot in black lines the data with no missing values. Then, I give the same points but with missing values; I use a trick redefining nan (or any user-defined flag) to simply get rid of them. However, the plot in red is not satisfying, because lines are connecting surrounding values. In blue, I plot "by hand" (i.e. by calling on several \listplot) the result I would like to get automatically; note that an isolated point can simply be discarded.


\savedata{\data}[1 2  2 1  3 1  4 2    5 1    6 2  7 3  8 1    9 2  10 3]

\savedata{\data}[1 2  2 1  3 1  4 nan  5 nan  6 2  7 3  8 nan  9 2  10 nan]
\pstVerb{/nan { pop } def} % nice trick to get rid of nan values
\pstScalePoints(1.,1.){}{.1 add} % some vertical shift to allow comparison

\pstScalePoints(1.,1.){}{.2 add} % some vertical shift to allow comparison
\savedata{\data}[1 2  2 1  3 1]
\savedata{\data}[6 2  7 3]
% the following goes wrong because isolated point is completed with (0,0)
% \savedata{\data}[9 2]
% \listplot[linecolor=blue]{\data} 

  • Is pstricks a requirement, or would a pgfplots method be of interest? Commented Apr 12, 2017 at 15:12
  • this is supposed to be used within a long pstricks macro (and this is why I do not want to resort to splitting in several \listplot commands), so I'd rather have a version that works with pstricks. Commented Apr 12, 2017 at 15:22
  • I see, then I won't waste your time with that. Commented Apr 12, 2017 at 15:25
  • thanks anyway! (and if I do not find a reasonable pstricks way of doing it, I might consider shifting to other graphical packages around) Commented Apr 12, 2017 at 15:27
  • @Torbjørn T. I got no luck so far, and I am pretty sure such functionality would be useful to others than me. If you ever get the time to detail a pgfplot alternative, I would take it as an answer. Commented Apr 24, 2017 at 7:21

2 Answers 2


pgfplots has this feature built in, with the option unbounded coords=jump.

I don't know where your data comes from. If you have them in a text file data.dat with the format

1 2 
2 1
3 1
4 nan

then you can use that directly in the \addplot command, as \addplot [unbounded coords=jump] table {data.dat};. If you have multiple columns in a file, you can select which ones to use with e.g. \addplot table[x index=0,y index=2] {data.dat};.

\pgfplotstableread{ % read in data
1 2 
2 1
3 1
4 nan
5 nan
6 2
7 3
8 nan
9 2
10 nan
% axis limits
% size of plot
% scale only axis means that 10cm is only the axis, not the ticks
width=10cm,height=4cm,scale only axis, 
% add grid
% plot data with gaps in line
\addplot [blue,very thick,unbounded coords=jump] table {\data};
% default setting, no gaps
\addplot [red,dashed] table {\data};

enter image description here

  • Built-in... I really like pstricks but this goes definitely in favor of pgf + tickz. Thanks. Commented Apr 24, 2017 at 9:39

\savedata{\data}[1 2  2 1  3 1  4 2  5 1 6 2  7 3  8 1 9 2  10 3]


enter image description here

  • I should have emphasized the automatic part of the feature I am looking for; at least, without having to split manually into several \listplot commands. I am thinking right away of a command preprocessing the data and generating suitable \listplot with appropriate nStart and nEnd, but my knowledge of both latex and postscript is too poor to make such a command from scratch Commented Apr 13, 2017 at 7:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .