3

目前我正在研究 Gnulot 堆叠填充曲线。我无法将我的图表堆叠起来。这是我的数据:

     prog   reli    perf    avail   sec cons    topo    scale   qos
2011 138    90.3    21.0    63.5    45.5    48.5    6.8 4.0 5.5
2012 191.3  77.8    90.8    30.8    29.0    22.1    2.0 1.0 1.0
2013 85.0   57.5    48.0    20.0    27.5    8.5 0   2.5 1.0
2014 2.0    0.5 1.0 2.0 1.0 1.5 0   0   0

我已经在 t1.plt 上绘制了

set term pos eps font 20
set output 't1.eps'
set pointsize 0.8
set border 11
set xtics out
set tics front
set key below
set multiplot
a=0
plot for [i=1:9] "t1" using (column(i)):xtic(1) t column(i) with filledcurves

我当前的输出:

输出

我期望创建像这个链接这样的图表: 期望输出

4

2 回答 2

5

以下是仅使用 gnuplot 的方法。您可以使用sum命令对列值求和以获得堆叠图:

set terminal postscript eps color font 20
set output 't1.eps'
set xtics 1 out
set tics front
set key invert
set style fill solid noborder
plot for [i=10:2:-1] "t1" using 1:(sum [col=2:i] column(col)) with filledcurves x1 title columnheader(i-1)

请注意,列标题的索引是 1..9,而值从 2..10 开始。所以你必须明确地使用title columnheader(i-1). 如果您还要给第一列一个标题,例如year,您可以使用set key autotitle columnheader.

不幸的是,该invert选项set key仅适用于列。因此,如果您使用set key below invert,则不会获得数据文件的原始顺序。

4.6.4 的结果:

在此处输入图像描述

于 2014-05-26T18:59:27.270 回答
3

风格注意事项:

x1在命令末尾添加,plot使曲线朝向(下)x 轴(x2将是上轴)闭合。另请注意,set multiplot在这种情况下,这是不必要的。最后,迭代中的标题应该来自column(i-1)而不是column(i),或者在数据文件的第一列中添加一个标签,并且迭代应该从 2 到 10 运行,除非您也想将第一列与自身进行对比。

使用您的数据和以下命令:

plot for [i=2:10] \
"t1" using (column(i)):xtic(1) t column(i-1) with filledcurves x1

我得到:

在此处输入图像描述

将图形堆叠起来有点复杂,因为它涉及添加连续的列,可以使用 awk 来完成,在 gnuplot 中调用:

set xtics 1
plot for [i=10:2:-1] \
"< awk 'NR==1 {print \"year\",$".(i-1)."} NR>=2 {for (i=2; i<=".i."; i++) \
{sum+= $i} {print $1, sum; sum=0} }' t1" \
using (column(2)):xtic(1) with filledcurves x1 t column(2)

在此处输入图像描述

您可以在 gnuplot 之外单独执行该awk部分,以查看它对您的数据的作用:

# This is for second column (col=2), change value of col variable to see other columns
awk 'col=2 {} NR==1 {print "year",$(col-1)} NR>=2 {for (i=2; i<=col; i++) {sum+= $i} {print $1, sum; sum=0} }' t1 
于 2014-05-26T09:14:51.890 回答