这是一个简单的数据文件data.csv
:
Time,Value
"2017-01-31 12:51:05",500
"2017-01-31 12:51:05",820
"2017-01-31 13:48:14",820
"2017-01-31 13:48:14",500
以下是它的简单情节:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in = x,
set layers,
every axis plot/.append style={on layer=pre main},
xticklabel = {\hour:\minute},
x tick label style = {align=center},
xlabel = X,
ylabel = Y,
ymin = 500.0,
ymax = 820.0
]
\addplot [color = black, fill = black, opacity = 0.2, draw opacity = 0] table [y=Value, col sep = comma]{data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
这会按照你期望的方式工作:
我想指定xmin
,xmax
和xtick
(显然需要添加date ZERO
):
\begin{axis}[
date coordinates in = x,
set layers,
every axis plot/.append style={on layer=pre main},
xticklabel = {\hour:\minute},
x tick label style = {align=center},
date ZERO = 2017-01-31 08:00,
xtick = {2017-01-31 09:30,2017-01-31 11:30,2017-01-31 13:30,2017-01-31 15:30},
xmin = 2017-01-31 08:00,
xmax = 2017-01-31 17:00,
xlabel = X,
ylabel = Y,
ymin = 500.0,
ymax = 820.0
]
现在我得到以下内容:
Error: ! Dimension too large.<recently read> \pgf@xx \end{axis}
! Dimension too large.\pgf@process #1->{#1\global\pgf@x = \pgf@x\global \pgf@y = \pgf@y }\end{axis}
…
但是当我评论时\addplot
,我得到:
哪个是正确的画布。为什么???
答案1
似乎与日期/时间周围的引号有关data.txt
,删除它们,你会得到
加上引号,\year
不知怎么就变成了 8215,而不是 2017。设置一下xticklabel = {\year-\month-\day--\hour:\minute}, x tick label style = {align=center,rotate=45}
就可以看到:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in = x,
set layers,
every axis plot/.append style={on layer=pre main},
xticklabel = {\hour:\minute},
x tick label style = {align=center},
date ZERO = 2017-01-31 08:00,
xtick = {2017-01-31 09:30,2017-01-31 11:30,2017-01-31 13:30,2017-01-31 15:30},
xmin = 2017-01-31 08:00,
xmax = 2017-01-31 17:00,
xlabel = X,
ylabel = Y,
ymin = 500.0,
ymax = 820.0
]
\addplot [color = black, fill = black, opacity = 0.2, draw opacity = 0]
table [y=Value, col sep = comma]{
Time,Value
2017-01-31 12:51:05,500
2017-01-31 12:51:05,820
2017-01-31 13:48:14,820
2017-01-31 13:48:14,500
};
\end{axis}
\end{tikzpicture}
\end{document}