如果指定了 xmin/xmax,则 Dateplot 不起作用

如果指定了 xmin/xmax,则 Dateplot 不起作用

这是一个简单的数据文件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}

这会按照你期望的方式工作:

在此处输入图片描述

我想指定xminxmaxxtick(显然需要添加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}

相关内容