1

I have some data that needs to be plotted against time. But the time is not absolute (NOT 0,1,2,3,...). So I want to represent x tick label as relative labels (like t, t+1, t+2, t+3, ...). My data set is large (around a million data points), So I cannot write it down manually for each data point as given in this community for some questions (example 1,example 2)

How can I achieve this goal?

4

You could use something like

xticklabel={
    \ifnum \ticknum=1 $t$
  \else
    \pgfmathparse{\ticknum-1} $t+\pgfmathprintnumber[fixed,precision=0]{\pgfmathresult}$
  \fi
}

Example:

\documentclass[margin=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
  xmin=0,
  xticklabel={
      \ifnum \ticknum=1 $t$
    \else
      \pgfmathparse{\ticknum-1} $t+\pgfmathprintnumber[fixed,precision=0]{\pgfmathresult}$
    \fi
  }
  ]
  \addplot[]{x^2};
  \end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Or you can use the suggestion by @Alenanno (see the comment below)

xticklabel={
    \ifnum \ticknum=1 $t$
  \else
   \pgfmathtruncatemacro\myticknum{\ticknum-1} $t+\myticknum$
  \fi
}
  • 2
    I think this might work too: \pgfmathtruncatemacro\mytick{\ticknum-1} $t+\mytick$ – Alenanno Jun 2 '16 at 13:36
  • @Alenanno Thanks for the hint. This is shorter and works too. – esdd Jun 2 '16 at 13:54

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.