[Tex/LaTex] How to change the number of major tick labels? (pgfplots)

pgfplots

I would like to keep only the year number when scaling up and omit the 200x.5 or any other appearing figures.

enter image description here

MWE

\documentclass{scrartcl}

\usepackage{
pgfplots,
amsmath
}

\usepackage[T1]{fontenc}
\usepackage{lmodern}

\def\parsedate#1-#2!{%
    \pgfmathparse{#1+1/12*(1#2-101)}%
}

\begin{filecontents*}{data.csv}
2006-01;611242
2006-02;611075
2006-03;609840
2006-04;608181
2006-05;605813
2006-06;604530
2006-07;601576
2006-08;598600
2006-09;595991
2006-10;593231
2006-11;589636
2006-12;594858
2007-01;590481
2007-02;588671
2007-03;586932
2007-04;582984
2007-05;578470
2007-06;574981
2007-07;569834
2007-08;566085
2007-09;563062
2007-10;559383
2007-11;556292
2007-12;563823
\end{filecontents*}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
height=5cm,
width=5cm,
%
xmin=2006-01,
xmax=2008-01,
%
xmajorgrids={true},
xminorgrids={false},
ymajorgrids={true},
yminorgrids={false},
%
minor x tick num=1,
%
x coord trafo/.code={\expandafter\parsedate#1!},
%
/pgf/number format/1000 sep={},
]
\addplot [mark=square*, mark indices={1,72},x=x,y=ind1] table [col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{center}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
height=5cm,
width=10cm,
%
xmin=2006-01,
xmax=2008-01,
%
xmajorgrids={true},
xminorgrids={false},
ymajorgrids={true},
yminorgrids={false},
%
minor x tick num=1,
%
x coord trafo/.code={\expandafter\parsedate#1!},
%
/pgf/number format/1000 sep={},
]
\addplot [mark=square*, mark indices={1,72},x=x,y=ind1] table [col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}

Best Answer

You can use the xtick key:

\documentclass{scrartcl}

\usepackage{
pgfplots,
amsmath
}

\usepackage[T1]{fontenc}
\usepackage{lmodern}

\def\parsedate#1-#2!{%
    \pgfmathparse{#1+1/12*(1#2-101)}%
}

\begin{filecontents*}{data.csv}
2006-01;611242
2006-02;611075
2006-03;609840
2006-04;608181
2006-05;605813
2006-06;604530
2006-07;601576
2006-08;598600
2006-09;595991
2006-10;593231
2006-11;589636
2006-12;594858
2007-01;590481
2007-02;588671
2007-03;586932
2007-04;582984
2007-05;578470
2007-06;574981
2007-07;569834
2007-08;566085
2007-09;563062
2007-10;559383
2007-11;556292
2007-12;563823
\end{filecontents*}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
height=5cm,
width=5cm,
%
xmin=2006-01,
xmax=2008-01,
%
xmajorgrids={true},
xminorgrids={false},
ymajorgrids={true},
yminorgrids={false},
%
minor x tick num=1,
xtick={2006-01,2007-01,2008-01},
%
x coord trafo/.code={\expandafter\parsedate#1!},
%
/pgf/number format/1000 sep={},
]
\addplot [mark=square*, mark indices={1,72},x=x,y=ind1] table [col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{center}
\begin{center}
\begin{tikzpicture}
\begin{axis}[
height=5cm,
width=10cm,
%
xmin=2006-01,
xmax=2008-01,
%
xmajorgrids={true},
xminorgrids={false},
ymajorgrids={true},
yminorgrids={false},
%
minor x tick num=1,
xtick={2006-01,2007-01,2008-01},
%
x coord trafo/.code={\expandafter\parsedate#1!},
%
/pgf/number format/1000 sep={},
]
\addplot [mark=square*, mark indices={1,72},x=x,y=ind1] table [col sep=semicolon] {data.csv};
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}

enter image description here

Related Question