Gnuplot,堆积区域和自定义抽动字符串

时间:2018-03-16 17:13:26

标签: perl gnuplot stacked-area-chart

所以,我有下一个问题。我正在为自己的Gnuplot包装器编写一个Perl插件,我需要绘制堆积区域图表,但这里有抽搐的问题。

我有以下数据文件(epoch中的日期 - 用于Perl函数):

date    c1  c2  c3  c4  c5  c6  c7  c8  c9  c10 c11 c12
1521230521  173 830 988 284 165 577 920 749 409 705 703 601
1521316921  501 691 883 573 325 152 499 526 417 708 259 587
1521403321  33  193 576 106 397 329 801 857 534 559 527 213
1521489721  827 186 910 412 688 650 13  201 222 150 468 353
1521576121  53  425 726 989 362 489 554 986 480 485 414 74
.....

我得到了这个脚本(使用Perl脚本中的变量,请注意这一点):

reset
set encoding utf8

set term pngcairo size $w, $h
set datafile separator "\\t"

set key autotitle
set key reverse Left outside
set key samplen 0.25 spacing 1 font "Roboto Mono Medium, 11"
set key bot center horiz
set key height 1

set output "img.png"

set xtics ("16 mar 22:45" 0, ...., "04 apr 22:45" 19) # string generated by perl
set xtics font "Roboto Mono Light, 9" nomirror out 
set ytics font "Roboto Mono Light, 9" nomirror out

set auto y
set tics front

# $rm # set rmargin
# $lm # set lmargin

set grid xtics ytics front
set style data filledcurves x1
set pointsize 0.8

plot for [i=2:".($cols+1).":1] '$datfile' using 1:(sum [col=i:".($cols+1)."] column(col)) title columnheader(i)

我需要抽动看起来像那样:

enter image description here

但抽搐没有出现:

enter image description here

您可能会问我为什么不使用set xdata time?这是因为如果有很多抽搐的情况下无法控制的抽动重叠。这就是我使用严格的预先计算对的原因:

set xtics ("16 mar 22:45" 0, "22 mar 23:02" 6, ...., "04 apr 22:45" 19)

这对直方图有用。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

你的抽搐超出了范围。 x轴上的实际值取自第1列,它们从1521230521开始,而不是从0开始。

使用正确的" pos"生成你的抽动。值:

set xtics ("16 mar 22:45" 1521230521, \
           "17 mar 22:45" 1521316921, \