我正在使用pgfplots
20 年内的月度数据绘制下图。但是,我对 x 轴上的标签不太满意。我希望步长为 3 年(例如1994, 1997, 2000, 2003, 2006, 2009, 2012
)。目前有 2 年和 3 年的步长。有人能帮忙吗?
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{width=8cm,compat=newest}
\usepgfplotslibrary{dateplot}
\begin{document}
\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
width=13cm, height=9cm,
date coordinates in=x,
xticklabel style={/pgf/number format/1000 sep=},
date ZERO=1993-01-01,
xticklabel={\year},
xmin={1993-01-01},
xmax={2013-11-01},
ymin=0.01,
ymax=30,
tick pos=left,
legend pos=outer north east,
legend cell align=left,
]
\addplot table[x=year,y=greece] {data.csv};\addlegendentry{Greece}
\addplot table[x=year,y=portugal] {data.csv};\addlegendentry{Portugal}
\addplot table[x=year,y=ireland] {data.csv};\addlegendentry{Ireland}
\addplot table[x=year,y=italy] {data.csv};\addlegendentry{Italy}
\addplot table[x=year,y=spain] {data.csv};\addlegendentry{Spain}
\addplot table[x=year,y=belgium] {data.csv};\addlegendentry{Belgium}
\addplot table[x=year,y=austria] {data.csv};\addlegendentry{Austria}
\addplot table[x=year,y=france] {data.csv};\addlegendentry{France}
\addplot table[x=year,y=netherlands] {data.csv};\addlegendentry{Netherlands}
\addplot table[x=year,y=germany] {data.csv};\addlegendentry{Germany}
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
答案1
您可以使用日期来xtick
指定您想要 xticks 的位置,例如
xtick = {
{1994-01-01},
{1997-01-01},
{2000-01-01},
{2003-01-01},
{2006-01-01},
{2000-01-01},
{2012-01-01}
}
将其添加到axis
选项中。