1

我使用以下方法绘制时间序列的数据(图像、吞吐量):

set term postscript color eps enhanced 22
set encoding utf8
set output "tput.eps"
load "../styles.inc"
set size 1,0.6
set bmargin 4.5
set tmargin 2.5
set lmargin 9
set rmargin 8
set title "{/bold Images updated and generated network traffic}" offset 0,0
set ylabel "#Images" offset 0,0
set y2label "Throughput [GB/day]" offset -2,0
set ytics 0,100,800
set ytics nomirror

set y2tics 0,100,600
set y2tics nomirror

set xtics time
set format x '%d/%m/%Y'

set grid y
set yrange[0:800]
set y2range [0:]
set xtics rotate by 45 right font "Arial, 18" nomirror
set key vertical sample 1.0 maxrows 1 width -0.6 at graph 1,1.13 font "Arial, 18"

set datafile separator ","
plot "datecount_sorted.csv" using (timecolumn(1, "%Y-%m-%d")):($2) with lines ls 5001 title "Uploaded images",\
     "datecount_sorted.csv" using (timecolumn(1, "%Y-%m-%d")):($3/(1024*1024*1024)) axis x1y2 ls 5002 title "Upload Throughput",\
                     
!epstopdf "tput.eps"
!rm "tput.eps"
quit 

输入数据如下所示:

2016-04-12,1,0
2016-05-02,2,0
2016-05-05,2,0
2016-05-06,1,0
2016-05-11,2,0
2016-05-13,3,0
2016-05-25,2,0
2016-06-01,3,541204241
2016-06-06,1,0
2016-06-13,1,471311979
2016-06-14,1,6329289
2016-06-17,1,137972881
2016-06-24,1,319050239
2016-06-27,1,138193384

输出是正确的,它看起来像这样: 在此处输入图像描述

问题是当我尝试设置 xrange 时,情节完全中断(不渲染)。特别是这种语法似乎是错误的:

set xrange ["2020-01-01":"2020-06-17"]

同样错误的是使用情节中使用的相同 timefmt 的那个:

set xrange ["01/01/2020":"17/06/2020"]

那么..什么是正确的语法?

4

2 回答 2

1

您缺少的是set xdata timeset timefmt <format string>告诉 gnuplot 如何从数据中读取日期,xrange 使用中指定的格式设置timefmt,它不必与format您给轴的格式相同,绘图会中断,因为它可以'不解码来自 xrange 的日期。在您的情况下,添加这应该就足够了

set xdata time
set timefmt "%Y/%m/%d"

set xrange ["2016/04/12":"2016/05/03"]在您发布的示例数据文件上对其进行了测试。

于 2020-07-17T10:48:05.930 回答
0

您必须明确解析传递给范围设置的时间字符串:

set xtics time
FMT="%Y-%m-%d"
set format x "%d/%m/%Y"
set xrange [strptime(FMT, "2016-01-01"):strptime(FMT, "2016-06-17")]

set datafile separator commna   
plot "datecount_sorted.csv" using (timecolumn(1, FMT)):2 with lines title "Uploaded images"
于 2020-07-17T08:54:10.113 回答