嵌入轴 Pgfplots

嵌入轴 Pgfplots

所以我需要按如下方式显示数据:一个月中的每一天我都有一组在不同时间获得的值。我希望轴包含日期,但在日期与日期之间,我希望显示从 00:00 到 24:00 的小时数。我就是想不通。如果有人能给我提示,我会很高兴。所以我使用以下代码,我只想在 x 轴上显示日期而不是小时数。

    \begin{tikzpicture}
 \begin{axis}[
        xlabel=$Time$,
        ylabel=$Availability (\%)$,
                date coordinates in=x,
                xtick=data,
                xticklabel style={rotate=90,anchor=near xticklabel},
                xticklabel=\day. \hour:\minute,
                date ZERO=2014-04-1 00:00,% <- improves precision!
                ]

                 \addplot[color=red,mark=x]
        plot coordinates {
                (2014-04-1 00:00, 100)
                (2014-04-1 02:00, 77)
                (2014-04-1 02:15, 62)
                (2014-04-1 15:00, 62)
                (2014-04-1 15:15, 62)
                (2014-04-1 15:30, 62)
                (2014-04-1 19:00, 62)
                (2014-04-2 07:00, 47)
                (2014-04-2 07:15, 11)
                (2014-04-2 11:00, 11)
                (2014-04-2 11:15, 11)
                (2014-04-2 11:30, 11)
        };
\end{axis}
\end{tikzpicture}

答案1

假设我正确理解了您的请求,这里有一种方法。这需要一点工作量,因为每个小时刻度都必须手动指定。

在此处输入图片描述

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
        xlabel=Time,
        ylabel=Availability (\%),
        date coordinates in=x,
        xticklabel style={rotate=90,anchor=near xticklabel},
        xticklabel=\day,
        xtick={2014-04-1, 2014-04-02},
        date ZERO=2014-04-1 00:00,% <- improves precision!
        extra x ticks={%
           2014-04-1 04:00,
           2014-04-1 08:00,
           2014-04-1 12:00,
           2014-04-1 16:00,
           2014-04-1 20:00,
           2014-04-2 04:00,
           2014-04-2 08:00,
           2014-04-2 12:00},
       extra x tick label=\hour:\minute
        ]

     \addplot[color=red,mark=x]
        plot coordinates {
                (2014-04-1 00:00, 100)
                (2014-04-1 02:00, 77)
                (2014-04-1 02:15, 62)
                (2014-04-1 15:00, 62)
                (2014-04-1 15:15, 62)
                (2014-04-1 15:30, 62)
                (2014-04-1 19:00, 62)
                (2014-04-2 07:00, 47)
                (2014-04-2 07:15, 11)
                (2014-04-2 11:00, 11)
                (2014-04-2 11:15, 11)
                (2014-04-2 11:30, 11)
        };
\end{axis}
\end{tikzpicture}
\end{document}

相关内容