如何避免在带线图中使用累积 y 值绘制非连续时间序列值

How to avoid the drawing of non consecutive time series values using cumulative y values in a with lines plot

对于此数据:

02/29/2020|2
03/01/2020|1
03/06/2020|1
03/07/2020|1
03/11/2020|5
03/12/2020|3

你怎么画这样的东西:

sample graph

如您所见,我的 x 时间数据从 3 月 7 日跳到 3 月 11 日,因此一个简单的 with lines 会将 3 月 7 日点连接到 3 月 11 日点,我不希望出现这种行为。最后,如何绘图才能使 x 和 y 对像这样

02/29/2020|2
03/01/2020|3
03/06/2020|4
03/07/2020|5
03/11/2020|10
03/12/2020|13

其中 y 不断添加其先前的值:

你能在你的数据中添加空行吗? 那么你可以这样做:

代码:

### plot cumulated data over time
reset session

myTimeFmt = "%m/%d/%Y"
set datafile separator "|"

$Data <<EOD
02/29/2020|2
03/01/2020|1

03/06/2020|1
03/07/2020|1

03/11/2020|5
03/12/2020|3
EOD

set format x "%m/%d" time
set style line 1 pt 7 lc rgb "red"
set yrange [0:]
set key top left

mySum = 0
plot $Data u (timecolumn(1,myTimeFmt)):(mySum=mySum+) w lp ls 1 title "cumulative"
### end of code

结果:

加法:

如果您需要在非连续的日期之间插入空行,您也可以使用 gnuplot 来完成。

### plot cumulated data over time (+ insert emtpy line after non-consecutive days)
reset session

myTimeFmt = "%m/%d/%Y"
set datafile separator "|"

Data = "$Data"          # if your data is in a file
# Data = "'Data.dat'"   # uncomment this line and enter your filename
                        # and skip the following datablock
$Data <<EOD
02/29/2020|2
03/01/2020|1
03/06/2020|1
03/07/2020|1
03/11/2020|5
03/12/2020|3
EOD

# create data with whitespace as column separator
set table $Data2
    plot @Data u (strcol(1)):2 w table
unset table

# with emtpy line between two non-consecutive days
set print $Data3
    do for [i=1:|$Data2|-1] {
        if (strptime(myTimeFmt,word($Data2[i+1],1)) > \
            strptime(myTimeFmt,word($Data2[i],1))+86400) \
           {print $Data2[i]; print '' }
        else {print $Data2[i]}
    }
    print $Data2[|$Data2|]
set print
print $Data3

set datafile separator whitespace
set format x "%m/%d" time
set style line 1 pt 7 lc rgb "red"
set yrange [0:]
set key top left

mySum = 0
plot $Data3 u (timecolumn(1,myTimeFmt)):(mySum=mySum+) w lp ls 1 title "cumulative"
### end of code

结果:(同上)