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?

1 Answers1

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
}
esdd
  • 85,675