[Tex/LaTex] pgfplots: plot smaller range of table and still use enlargelimits=true

pgfplots

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:

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}

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

\end{document}

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…

Best Answer

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).

Related Question