Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Please consider the following example code:

\documentclass{article}
\usepackage{pgfplotstable}

\pgfplotstableread{
1   19.178  26.027  8.219   6.849   39.726  1
2   54.795  21.918  4.110   6.849   12.329  1
3   28.767  16.438  6.849   8.219   39.726  1
4   63.014  2.740   2.740   8.219   28.767  2
5   90.411  1.370   6.849   0.000   1.370  2
6   15.068  2.740   16.438  8.219   57.534  2
7   67.123  0.000   0.000   1.000   32.877  3
8   72.603  6.849   5.479   5.000   15.068  3
9   56.164  12.329  6.849   4.110   20.548  3
10  50.685  4.110   8.219   1.370   35.616  3
}\datatable

\begin{document}

\begin{tikzpicture}
\begin{axis}
\addplot table[x index=0,y index=4] \datatable;
\end{axis}
\end{tikzpicture}

\end{document}

Producing

enter image description here

What I want to do is to interrupt the plot, without modifying the table (if possible), at desired locations to get something like this (I obtained the image by manually erasing some connecting lines):

enter image description here

Ideally, I'd like to do this with just one \addplot, but if that's not possible, any alternatives are welcome.

share|improve this question
    
Normally empty lines in the data, where you want the jump, should do the trick, but for some reason it only works for inline data, a la \addplot table {<actual data>};. –  Henri Menke Mar 23 at 19:18
    
@HenriMenke Thanks for that. However, I don't want to change the table. –  Gonzalo Medina Mar 23 at 19:21
    
A concept: You could use something like x expr=\thisrowno{0} but hook into \thisrowno to place unbound values at desired points. I am thinking of it like x expr=\discontrow{0}{{3,4},{5,6}}. Then discontrow calls \thisrow{0} but places a row with only nan between rows 3 & 4 and rows 5 & 6. I just have no idea how to do that, because the definitions behind \thisrowno are nearly untraceable in the source. –  Henri Menke Mar 23 at 21:44
    
Is it OK to transpose the table and insert dummy columns then transpose back? :P –  percusse Mar 23 at 23:20
    
@percusse if all of that can be done internally (using \datatable) and not directly changing the actual data table, then it's OK. –  Gonzalo Medina Mar 23 at 23:35

1 Answer 1

up vote 4 down vote accepted

I can think of two options:

1) If you can modify your table an easy fix is to add somesort of undefined data and use the option unbounded coords=jump. Either "nan" or "inf" will work. I don't post the result because it looks exactly like you want:

\documentclass{article}
\usepackage{pgfplotstable}

\pgfplotstableread{
1   19.178  26.027  8.219   6.849   39.726  1
2   54.795  21.918  4.110   6.849   12.329  1
3   28.767  16.438  6.849   8.219   39.726  1
nan   nan  nan  nan   nan   nan  nan
4   63.014  2.740   2.740   8.219   28.767  2
5   90.411  1.370   6.849   0.000   1.370  2
6   15.068  2.740   16.438  8.219   57.534  2
nan
7   67.123  0.000   0.000   1.000   32.877  3
8   72.603  6.849   5.479   5.000   15.068  3
9   56.164  12.329  6.849   4.110   20.548  3
10  50.685  4.110   8.219   1.370   35.616  3
}\datatable

\begin{document}

\begin{tikzpicture}
\begin{axis}[unbounded coords=jump]
\addplot table[x index=0,y index=4] \datatable;
\end{axis}
\end{tikzpicture}

\end{document}

2) If the table CANNOT be modified I suggest splitting the plot and definining domains. This is not without problems because you will have to repeat the format in these, (like [red, solid, thick,...])

\begin{tikzpicture}
\begin{axis}
\addplot+[forget plot] table[x index=0,y index=4, restrict x to domain=0:3] \datatable;
\addplot+[forget plot] table[x index=0,y index=4, restrict x to domain=4:6] \datatable;
\addplot+[           ] table[x index=0,y index=4, restrict x to domain=7:10] \datatable;
\end{axis}
\end{tikzpicture}
share|improve this answer
    
Thanks, but I'm looking (as stated in the question) for an option not involving modifications to the data table. –  Gonzalo Medina Mar 23 at 19:43
    
Ah, my bad. I leave it because some else can find it useful, did you try with filters? –  alfC Mar 23 at 19:45
    
No problem. If a solution without modifications to the table is not possible, this is a valid alternative :) Yes, I tried with filters but didn't manage to get the desired results; I am not very familiar with their use. –  Gonzalo Medina Mar 23 at 19:47
    
Well, if you don't want to modify the table you will have to enter the ranges somehow. I suggest splitting the plots and defining the domains. See my edit. –  alfC Mar 23 at 19:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.