2017-08-07 112 views
0
tmp.data 
DATE   D0 D1 D2 D3 D4 D5 
"2017-07-19" 10 8 6 4 2 1 
"2017-07-20" 16 14 10 11 10 9 
"2017-07-21" 6 5 4 4 3 1 
"2017-07-22" 7 5 4 4 3 2 
"2017-07-23" 8 6 4 2 1 1 

tmp.gnu 
set terminal png size 
set output 'output.png' 
set title "statistics" 
set key font ",10" 
D0 = "#99ffff"; D1 = "#4671d5"; D2 = "#ff0000"; D3 = "#f36e00"; D4 = "#8A2BE2#'; D5 = "#4671d5" 
set auto x 
unset xtics 
set xtics nomirror rotate by -45 scale 0 
set style data histogram 
set style histogram rowstacked 
set style fill solid border -1 
set boxwidth 0.75 
plot 'tmp.data' u 2:xtic(1) title columnheader, \ 
'' u 3:xtic(1) title columnheader, \ 
'' u 4:xtic(1) title columnheader, \ 
'' u 5:xtic(1) title columnheader, \ 
'' u 6:xtic(1) title columnheader, \ 
'' u 7:xtic(1) title columnheader 

创建以下: enter image description heregnuplot的堆积条形图算术

的列是累计。 我想什么有是有它的比例,例如在第2行

10 - 8 = 2, 
8 - 6 = 2, 
6 - 4 = 2, 
4 - 2 = 2, 
2 - 1 = 1 
+0

而第二列中的值应该如数据文件中给出的那样? – Christoph

+0

其他列正在成正比 – 2fishandchips

+0

我在询问_columns_。你的例子显示,而不是第3列,你想要第3列和第2列之间的差异。这可以通过使用($ 2 - $ 3):xtic(1)',并相应地与第4列和更大。但对于第2栏没有参考价值。所以应该省略,还是将其用于数据文件中? – Christoph

回答

0

如果你想绘制两列之间的差异,那么你必须计算像

using语句中的差异
plot "tmp.data" using ($2 - $3):xtic(1) 

绘制第三和第二列之间的差异。为了您的所有列,并保持第二的是,使用(使用内联数据$data需要5.0):

$data <<EOD 
DATE   D0 D1 D2 D3 D4 D5 
"2017-07-19" 10 8 6 4 2 1 
"2017-07-20" 16 14 10 11 10 9 
"2017-07-21" 6 5 4 4 3 1 
"2017-07-22" 7 5 4 4 3 2 
"2017-07-23" 8 6 4 2 1 1 
EOD 

set xtics nomirror rotate by -45 scale 0 
set style data histogram 
set style histogram rowstacked 
set style fill solid border -1 
set boxwidth 0.75 
set key auto columnheader 
plot $data u 2:xtic(1), \ 
    for [i=3:7] '' u (abs(column(i) - column(i-1))):xtic(1) 

在这里,如果你需要abs或者不是你必须决定。结果是:

enter image description here

+0

谢谢克里斯托夫,我必须玩弄$ a $ b ...变数 – 2fishandchips