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 am using pgfplots to plot two simple (x,y)-plots of the same data from a table file. The first plot shows all of the data points and in the second plot I want to zoom in on some specific range of the data. However when I use xmin and xmax to restrict the range the first and last point gets placed on the axis box. I want to add a little space between the axes and the points so I try to set enlargelimits=true but then points outside the range gets shown and are not clipped away as I thought they would be.

Is there a way to do this without having to copy the desired data-point into a new table?

Heres an example of what I try to do: I have the data file plotdata.dat:

# plotdata.dat
x   y
0   0
1   1
2   4
3   9
4   16
5   25
6   36
7   49
8   64
9   81
10  100
11  121
12  144

And my latex document looks like this:



\begin{axis}[xmin=1, xmax=11, enlargelimits=true]
\addplot[only marks] table[x index=0, y index=1] {plotdata.dat};


Then even though xmin=1 the plot shows also the x=0 point. I don't want to just set the axis limits so that only the range is shown but instead ignore points outside the range...

share|improve this question
Welcome to LaTeX! Welcome to TeX.sx! Please add a minimal working example (MWE) that illustrates your problem. Also search for the enlargelimits command in the pgfplots manual for different options regarding the axis scales etc. – percusse Aug 5 '12 at 14:30
Thanks! I've already looked through the manual and tried different options but they don't seem to help me. I'll edit my question to show an example... – Filip A Aug 5 '12 at 15:23

The displayed range is independent of the set of data points which are being displayed.

In other words: even if you choose xmin and xmax in a way which hides all data points, pgfplots will still draw every data point.

If you want to select/discard subsets of your data points, you should study the filtering mechanisms, in particular: the restrict x to domain=1:9999 key with appropriate values. Filtering means to drop single coordinates. The unbounded coords=discard|jump key controls how pgfplots should react (either as if it never saw the discarded points at all or by introducing jumps).

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.