# pgfplot plot difference in x axis

I have a bunch of data where the x-axis is in seconds. I want to plot a snippet of this data, which means the starting point is going to be a pretty high number:

example of snippet test.csv:

X   Y
28600.13103 11
28602.81423 17
28605.80943 23
28606.85463 25
28607.89983 27
28608.75783 49
28609.77183 51
28610.80143 33
28612.09623 10
28614.73263 41
28617.08823 45
28618.38303 48
28619.84943 50


So if this is plottet with following MWE:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
scaled y ticks=false,
enlarge x limits=false]
\addplot +[mark=none] table[col sep=tab,x expr=\thisrowno{0},y={Y}] {test.csv};
\end{axis}
\end{tikzpicture}

\end{document}


The x-axis resolution becomes really bad:

And I don't have room for non shortened values.

So is there a way to plot only the difference in seconds and then having a node in each end telling which hour its in?

• I guess you already know this, but maybe it can be useful. A manual (i.e. not automatic) solution could be to use x expr=\thisrowno{0}-28600.13103, where the number is taken from the first data row. – LucaD Dec 3 '15 at 12:39
• thank's @LucaD I actually didn't think about that. This would do the trick, but an automatic method would be preferred – Rasmus Dec 3 '15 at 12:53

Is this automatic enough? I don't know exactly what kind of output you had in mind.

\documentclass[border=4mm]{standalone}
\usepackage{pgfplots,pgfplotstable,filecontents}

\begin{filecontents*}{data.dat}
X   Y
28600.13103 11
28602.81423 17
28605.80943 23
28606.85463 25
28607.89983 27
28608.75783 49
28609.77183 51
28610.80143 33
28612.09623 10
28614.73263 41
28617.08823 45
28618.38303 48
28619.84943 50
\end{filecontents*}

\pgfplotstablegetelem{0}{X}\of{\mydata}
\pgfmathsetmacro{\startsec}{\pgfplotsretval}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
clip mode=individual,
scaled y ticks=false,
enlarge x limits=false]
\addplot +[mark=none] table[x expr={\thisrowno{0}-\startsec},y=Y] {\mydata};
\node [below=0.6cm,anchor=east] at (rel axis cs:1,0) {$+\startsec\,\mathrm{s}$};
\end{axis}
\end{tikzpicture}
\end{document}

• Thanks @Torbjørn T. I don't have anything specific in mind, but it contains some methods that I defenetly will use in my application. – Rasmus Dec 4 '15 at 7:38