TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to make a plot of several data sets that are stored in a text file (tab-separated). Is there a way of defining the x-range for which some (not all) of the data sets should be plotted? I want some data sets to plot fully, and others only in specified ranges.

Consider the following example:

The table:

x B C D

1 3 4 5

2 4 6 3

3 4 7 4

4 5 7 2

should be plotted so that all four values of columns B and C are plotted against the x values, but only the values for which x is in the range [2,3] should be plotted for column D.

In other words, I want to use \addplot three times in the same axis environment, and define the x-range separately for each data set.

The condition cannot be the index. I need to use this for large data files, for which I do not know the indices of the data points I need. Hence, the input to define the points to plot must be an x interval.

share|improve this question
up vote 11 down vote accepted

You can use the key restrict x to domain=<start>:<end>, which installs a filter that removes all data points outside the specified range:



x B C D
1 3 4 5
2 4 6 3
3 4 7 3
4 5 7 2

\addplot table [y=B] {\datatable};
\addplot table [y=C] {\datatable};
\addplot +[restrict x to domain=2:3] table [y=D] {\datatable};
share|improve this answer

Your Answer


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.