gnuplot - 绘制堆叠线图

4
我使用内部基准测试工具。我使用 gnuplotgnuplot 4.6 patchlevel 4)进行可视化。
我需要将结果(多次运行的方法执行时间)表示为堆积线图,类似于以下内容:

example stacked line chart

这是我 .tsv 数据文件的摘录:

Run MethodA MethodB MethodC 
1   192 171 152
2   227 178 161
...
10  229 161 149

我正在使用的脚本:

#!/usr/bin/gnuplot -p

reset
clear

set terminal png size 640,480
set output "timings.png"
set key top left outside horizontal autotitle columnhead
set title "Third-party REST calls"

set xlabel "Run (ordinal)"
set xtics nomirror scale 0

set ylabel "Time (milliseconds)"
set ytics out nomirror

set grid ytics lt 0 lw 1 lc rgb "#bbbbbb"

set style data histogram
set style histogram rowstacked
set style fill solid border -1
set boxwidth 0.75

plot  "timings.tsv" using 2:xticlabels(1) , "" using 3, "" using 4

我得到以下结果:

histogram

是的,这不是一条线图而是柱状图(我需要表示每个方法执行时间的百分比)。我需要稍微不同的结果(相同的直方图,但不是用盒子而是用连接盒子顶部的线和线下的填充物),就像这样:

stacked line diagram - desired diagram

我知道使用filledcurve的方法(例如,在GNUPlot中创建填充堆栈图中描述),但在那种方法中,您需要明确地对值求和。

是否可以通过gnuplot绘制填充区域而不是框,例如将直方图转换为堆叠线图?


1
是的,你必须明确地求和,但使用plot forsum函数非常容易,就像你链接的那个页面上所示。 - Christoph
1个回答

3

您确实需要明确地对值求和,但这并不是一个大问题。您可以很容易地编写脚本:

firstcol=2
cumulated(i)=((i>firstcol)?column(i)+cumulated(i-1):(i==firstcol)?column(i):1/0)
plot "file.dat" using 1:(cumulated(4)), "" using 1:(cumulated(3)), "" using 1:(cumulated(2))

它不仅适用于3个数据列,我还成功地对6个列求和。使用 ... using 1:(cumulated(4)), "" using 1:(cumulated(3)) ... 的唯一缺点是列标题消失了,因此图例被省略了。但是很容易恢复它,只需为每个列添加标题,像这样:... using 1:(cumulated(4)) title columnhead(4), "" using 1:(cumulated(3)) title columnhead(3) ... 非常感谢。 - flaz14
1
它适用于任何列数,并且“firstcol”允许您定义要求和的序列的第一列。但是跳过某些列可能会有点尴尬。与filledcurve结合使用时,逆序也很有用。 - Joce NoToPutinsWarInUkraine

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接