1

enter image description here

I want my graph to only show the following time periods 1986, 1992, 1998, 2004, 2010, 2016, instead of the ones shown in the graph. Someone knows a solution? Thanks!

The data in .dat-file is in the format:

date value
1986-03-01 0.11
1986-06-01 0.45
...
2016-03-01 0.78

Latex code:

\usepackage{pgfplots}
\usepackage{amsthm, amsfonts, amsmath, amssymb, mathrsfs, enumerate,graphicx}
\usepackage{subcaption}
\usepgfplotslibrary{dateplot}
\usepackage{filecontents}
\pgfplotsset{height=5cm,width=8cm,compat=newest}
\usepgfplotslibrary{dateplot}

\begin{figure}[H]
\begin{subfigure}{.5\linewidth}\centering
\begin{tikzpicture}
\begin{axis}[legend style={at={(0.5,-0.35)},anchor=north},
  date coordinates in=x,
  x tick label style={/pgf/number format/1000 sep=},
  xticklabel={\year},
  ylabel=,
  xlabel=Time,
  enlargelimits=0.10,
  legend columns=1,
]
\addplot[no markers, color=black]
  table [x=date, y index=1] {msardhp.dat};
\legend{}
\end{axis}
\end{tikzpicture}
\end{subfigure}%
\caption{}
\end{figure}
Stefan Pinnow
  • 29,535
Name
  • 11

1 Answers1

1

You can specify tick locations with xtick as with normal axes, just use valid date format strings. I also had to set date ZERO to make it work. Finally, I removed the x tick label style, it doesn't have any effect here.

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{height=5cm,width=8cm,compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[legend style={at={(0.5,-0.35)},anchor=north},
  date coordinates in=x,
  xticklabel={\year},
  date ZERO={1986-01-01},
  xtick={%
    1986-01-01,
    1992-01-01,
    1998-01-01,
    2004-01-01,
    2010-01-01,
    2016-01-01%
},
%  ylabel=,
  xlabel=Time,
  enlargelimits=0.10,
  legend columns=1,
]
\addplot[no markers, color=black]
  table [x=date, y index=1] {
date value
1986-03-01 0.11
1986-06-01 0.45
2016-03-01 0.78
};
\legend{}
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Torbjørn T.
  • 206,688