配置 gnuplot 来处理像 excel 这样的时间序列

configure gnuplot to handle timeseries like excel

我正在尝试使用 gnuplot 绘制随时间推移发生的事件。 Excel 的默认行为会生成更具可读性的图表。

我希望 gnuplot 中的图表看起来像 Excel 的图表。

set terminal png size 1200,800
set xdata time
set timefmt "%Y-%m-%d_%H-%M"
set output "graph.png"
set xrange ["2015-02-01_08-54":"2015-02-01_23-20"]
set yrange [0:70]
set grid
set xlabel "24-Hour"
set ylabel "Events"
set title "Events"
plot "events.dat" using 1:2 index 0 title "events" with filledcurves ls 1

我花了很多时间处理源数据和 plot.conf,但是 我不清楚 Excel 有什么不同。

Gnuplot 输出:

gnuplot output

Excel 输出:

Excel output

Excel 使用错误的 x 尺度绘图:它忽略时间值,并将第一列中给出的值作为标签等距 x 值。

要获得与 gnuplot 相同的行为,您必须使用 xticlabel 将第一列中的值作为 tic 标签,并使用行号(第 0 列)作为 x 值:

set xtics rotate by 90 right noenhanced
plot "events.dat" using 0:2:xticlabel(1) title "events" with filledcurves

现在,这会给您带来难以阅读的标签,因为标签太多了。通过一些调整,您可以获得更好的结果:

set terminal pngcairo size 1200,800
set output "graph.png"
set yrange [0:70]
set grid y
set xlabel "24-Hour"
set ylabel "Events"
set xtics out nomirror scale 0.5 rotate by 90 right font ',8' noenhanced
plot "events.dat" using 0:2:xticlabel(int([=11=]) % 5 == 0 ? strcol(1) : '') title "events" with filledcurves

免责声明: 请仅使用此脚本来理解 Excel 的作用,而不是复制它,因为它给人的实际时间跨度的印象非常错误你的活动发生了!