绘制统计数据,将年份放在 Xticklabel PGFplot

绘制统计数据,将年份放在 Xticklabel PGFplot

我想绘制这些数据,但我不知道如何将年份放在 X 轴上,我想显示所有年份,而不是以 5 年为单位。

\begin{tikzpicture}
\begin{axis}[width=8cm,
x tick label style={
/pgf/number format/1000 sep=},
ylabel=Tonnes,
]
\addplot
coordinates {(1992,205.0)
(1993,297.0)
(1994,395.0)
(1995,1601.0)
(1996,213.0)
(1997,241.0)
(1998,203.0)
(1999,372.0)
(2004,300.26)
(2005,446.17)
(2006,530.4)
(2007,591.38)
(2008,948.04)
(2009,596.01)
(2010,768.448)
(2011,978.0)
(2012,1050.0)};
\end{axis}
\end{tikzpicture}

我在手册上读到有关函数 { \year.} 的内容,并尝试了它,但没有用。谢谢

答案1

你不需要dateplot这个。只需xtck=data

xticklabel style=
{/pgf/number format/1000 sep=,rotate=60,anchor=east,font=\scriptsize},

完整代码如下:

\documentclass{book}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
  \begin{tikzpicture}
\begin{axis}[width=8cm,
xtick=data,
xticklabel style=
{/pgf/number format/1000 sep=,rotate=60,anchor=east,font=\scriptsize},
ylabel=Tonnes,
]
\addplot
coordinates {(1992,205.0)
(1993,297.0)
(1994,395.0)
(1995,1601.0)
(1996,213.0)
(1997,241.0)
(1998,203.0)
(1999,372.0)
(2004,300.26)
(2005,446.17)
(2006,530.4)
(2007,591.38)
(2008,948.04)
(2009,596.01)
(2010,768.448)
(2011,978.0)
(2012,1050.0)};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容