Gnuplot:如何使用设置的 xtics 时间设置 xrange?
Gnuplot: how to set xrange with set xtics time?
我绘制了数据的时间序列(图像、吞吐量),使用的是:
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")):() with lines ls 5001 title "Uploaded images",\
"datecount_sorted.csv" using (timecolumn(1, "%Y-%m-%d")):(/(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"]
那么..正确的语法是什么?
您必须明确解析传递给范围设置的时间字符串:
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"
你缺少的是 set xdata time
和 set timefmt <format string>
来告诉 gnuplot 如何从数据中读取日期,xrange 是使用 timefmt
中指定的格式设置的,它不不必与您提供给轴的 format
相同,情节会中断,因为它无法解码 xrange 中的日期。
在你的情况下添加这个就足够了
set xdata time
set timefmt "%Y/%m/%d"
我在您发布的示例数据文件上使用 set xrange ["2016/04/12":"2016/05/03"]
对其进行了测试。
我绘制了数据的时间序列(图像、吞吐量),使用的是:
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")):() with lines ls 5001 title "Uploaded images",\
"datecount_sorted.csv" using (timecolumn(1, "%Y-%m-%d")):(/(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"]
那么..正确的语法是什么?
您必须明确解析传递给范围设置的时间字符串:
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"
你缺少的是 set xdata time
和 set timefmt <format string>
来告诉 gnuplot 如何从数据中读取日期,xrange 是使用 timefmt
中指定的格式设置的,它不不必与您提供给轴的 format
相同,情节会中断,因为它无法解码 xrange 中的日期。
在你的情况下添加这个就足够了
set xdata time
set timefmt "%Y/%m/%d"
我在您发布的示例数据文件上使用 set xrange ["2016/04/12":"2016/05/03"]
对其进行了测试。