答案1
问题出在stack plots=y
命令上。如果删除该选项,配置文件将看起来像时间序列数据。以下是最小工作示例:
\documentclass[a4paper,10pt]{article}
\usepackage{pgfplots}
\usepackage[active,pdftex,tightpage]{preview}
\PreviewEnvironment[{[]}]{tikzpicture}
\pgfplotsset{width=7cm, compat=1.13}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot}
\usepackage{eurosym}
\begin{document}
\pgfplotstabletypeset[string type]{plotdata/accounts.dat}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xticklabel={\day.\month.},
xlabel={2008},
%stack plots=y,
yticklabel={\pgfmathprintnumber{\tick}\EUR{}},
ylabel=Total credit,
ylabel style={yshift=10pt},
legend style={
at={(0.5,-0.3)},anchor=north,legend columns=-1}
]
\addplot table[x=date,y=account1] {plotdata/accounts.dat};
\addplot table[x=date,y=account2] {plotdata/accounts.dat};
\addplot table[x=date,y=account3] {plotdata/accounts.dat};
\legend{Giro,Tagesgeld,Sparbuch}
\end{axis}
\end{tikzpicture}
\end{document}
只需将此代码复制到 .tex 文件中,然后创建包含以下内容的accounts.dat
文件(将该文件放在子文件夹中):plotdata
date account1 account2 account3
2008-01-03 60 1200 400
2008-02-06 120 1600 410
2008-03-15 -10 1600 410
2008-04-01 1800 500 410
2008-05-20 2300 500 410
2008-06-15 800 1920 410
构建你的 .tex 文件,你应该得到类似这样的内容:
答案2
这没错,但这是一个stack plot
累积显示方式,因此每个帐户都以累积方式显示。您可以stack plot=y
在下一页的示例中看到该选项。
以下是可以在 CTAN 上找到的源文件(也在评论中)
\documentclass{article}
% translate with >> pdflatex -shell-escape <file>
% This file is an extract of the PGFPLOTS manual, copyright by Christian Feuersaenger.
%
% Feel free to use it as long as you cite the pgfplots manual properly.
%
% See
% http://pgfplots.sourceforge.net/pgfplots.pdf
% for the complete manual.
%
% Any required input files (for <plot table> or <plot file> or the table package) can be downloaded
% at
% http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/
% and
% http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/plotdata/
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pagestyle{empty}
\usepackage{pgfplotstable}
\usepgfplotslibrary{dateplot}\usepackage{eurosym}
\begin{document}
% requires \usepgfplotslibrary{dateplot} !
\pgfplotstabletypeset[string type]{accounts.dat}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x,
xticklabel={\day.\month.},
xlabel={2008},
stack plots=y,
yticklabel={\pgfmathprintnumber{\tick}\EUR{}}, % <- requires \usepackage{eurosym}
ylabel=Total credit,
ylabel style={yshift=10pt},
legend style={
at={(0.5,-0.3)},anchor=north,legend columns=-1}]
\addplot table[x=date,y=account1] {accounts.dat};
\addplot table[x=date,y=account2] {accounts.dat};
\addplot table[x=date,y=account3] {accounts.dat};
\legend{Giro,Tagesgeld,Sparbuch}
\end{axis}
\end{tikzpicture}
\end{document}
并且 accounts.dat 是
date account1 account2 account3
2008-01-03 60 1200 400
2008-02-06 120 1600 410
2008-03-15 -10 1600 410
2008-04-01 1800 500 410
2008-05-20 2300 500 410
2008-06-15 800 1920 410