Pgfplots:绘制没有缺失数据的时间序列

Pgfplots:绘制没有缺失数据的时间序列

我有时间序列数据,想用 pgfplots 绘制。数据仅涵盖工作日,因此不包括周末。pgfplots 仍然会为基本没有数据的数据点插入新的刻度,这会导致图表中的周末出现“空白区域”(见下文)。是否有可能改变这种行为,以便不生成这些空白刻度?在此处输入图片描述

母语:

\documentclass{article}%
\usepackage{graphicx}
\usepackage{pgfplots}
\usepackage{rotating}
\usepgfplotslibrary{dateplot} 
\usepackage{pgfplotstable}
\usepackage{filecontents}
\begin{filecontents}{mwe.csv}
Date,a,b
2008-01-02 00:00,15847.5,3784
2008-01-03 00:00,19345.5,5761.5
2008-01-04 00:00,20055,5611.5
2008-01-07 00:00,18907.5,4608.5
2008-01-08 00:00,20613.5,5155.5
2008-01-09 00:00,22102,4956.5
2008-01-10 00:00,23949,5034
2008-01-11 00:00,15518,4168.5
2008-01-14 00:00,19858,5504
2008-01-15 00:00,26947,7926
2008-01-16 00:00,24994,6592.5
2008-01-17 00:00,27077.5,6529.5
2008-01-18 00:00,38022.5,10623.5
2008-01-21 00:00,45479,12335
2008-01-22 00:00,38043,10338.5
2008-01-23 00:00,27517.5,7620
2008-01-24 00:00,29803.5,5838.5
2008-01-25 00:00,32695.5,4921
2008-01-28 00:00,19122,5384
2008-01-29 00:00,16761.5,3976.5
2008-01-30 00:00,19546,5519.5
2008-01-31 00:00,21879.5,5624.5
2008-02-01 00:00,15205,4113
2008-02-04 00:00,23555.5,5067.5
2008-02-05 00:00,27960.5,5217.5
2008-02-06 00:00,31158,5738.5
2008-02-07 00:00,24475,4778.5
2008-02-08 00:00,22286,4697
2008-02-11 00:00,22962,5735
2008-02-12 00:00,21080,4979
2008-02-13 00:00,19351.5,4378.5
2008-02-14 00:00,20144,4555.5
2008-02-15 00:00,13511,2853.5
2008-02-18 00:00,19149.5,4604.5
2008-02-19 00:00,22329,4072.5
2008-02-20 00:00,18542.5,3991
2008-02-21 00:00,23080.5,4690
2008-02-22 00:00,18790,3574.5
2008-02-25 00:00,21891.5,5164
2008-02-26 00:00,20662.5,4645.5
2008-02-27 00:00,21164,4491.5
2008-02-28 00:00,24220,4372
2008-02-29 00:00,22114.5,4449.5
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
date coordinates in=x, 
xticklabel={\begin{turn}{45}\day.\month.\year \end{turn}\\},
x tick label style={align=center},
ymajorgrids,
xmin={2008-01-01 00:00},
xmax={2008-02-20 22:00},
ymin=0,
legend pos=north west,]
\addplot [ycomb,color=black!70] table [col sep=comma,trim cells=true,y=a] {mwe.csv}; \addlegendentry{a}
\addplot [ycomb,color=black!30] table [col sep=comma,trim cells=true,y=b] {mwe.csv}; \addlegendentry{b}
\end{axis}
\end{tikzpicture}
\end{document}

相关内容