4

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}
\pgfplotsset{height=6cm,width=10cm,compat=newest}
\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:

enter image description here

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
4

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

enter image description here

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

\pgfplotsset{height=6cm,width=10cm,compat=newest}
\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*}
\pgfplotstableread{data.dat}\mydata

\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

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.