2

Is there any options to replace each nth point={100} for something dependent on column value?

My table is something like:

x   y
0   5
1   4
2   5
3   3
3   -3
2   -4
1   -1
0   0

I just want to plot for x values lower than 2.

(Of course it is a minimial situation, in the complete situation it is not so easy to modify the table and I use the other values inside the same axis).

0
4

Here is the first option using restrict x to domain=0:2

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usepackage{pgfplotstable}
\pgfplotstableread{ % Read the data into a table macro
x   y
0   5
1   4
2   5
3   3
3   -3
2   -4
1   -1
0   0
}\mydata

\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot+[restrict x to domain=0:2] table [x=x,y=y]
{\mydata};
%
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

And using xmax

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat = newest}
\usepackage{pgfplotstable}
\pgfplotstableread{ % Read the data into a table macro
x   y
0   5
1   4
2   5
3   3
3   -3
2   -4
1   -1
0   0
}\mydata

\begin{document}
\begin{tikzpicture}
\begin{axis}[xmax=2]
\addplot table [x=x,y=y]
{\mydata};
%
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

There is always a possibility that you can write some complex comparing routine using x expr macro, but I will leave it now.

1
  • The first option Harish told is better when the other data of the table is used in the same axis (the case I was searching for). – Ernesto Jun 2 '14 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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