我如何更改主刻度标签的数量?(pgfplots)

我如何更改主刻度标签的数量?(pgfplots)

我希望在放大时仅保留年份数字并省略 200x.5 或任何其他出现的数字。

在此处输入图片描述

平均能量损失

\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}

答案1

您可以使用以下xtick密钥:

\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}

在此处输入图片描述

相关内容