Gnuplot:具有不同键的多个直方图

时间:2012-06-12 14:55:41

标签: plot gnuplot histogram

我想使用gnuplot在同一个图上绘制多个rowstacked直方图。示例数据文件如下:

App1 20 30 50
App2 10 20 70

我使用的脚本就是这个

set terminal jpeg medium
set output "histo.jpeg"
set boxwidth 0.75 absolute
set style fill solid 1.00 border -1
set style data histogram
set style histogram rowstacked
set xtics 1000 nomirror
set ytics 100 nomirror
set mxtics 2
set mytics 2
set ytics 10
set yrange [0:120]
set ylabel "Total time"
set key below vertical

plot 'data' using 2 t "Idle", '' using 3 t "User space", '' using 4 :xtic(1) t "Kernel space"

我得到的结果是:enter image description here

我想在每个直方图下面有单独的键,因为我想显示每个元素占用的时间量,这是从一个图形到另一个图形的不同。此外,一个直方图上出现的某些元素可能不会出现在另一个直方图上。

我的目的是创建一个脚本,生成数据文件和gnuplot脚本以自动执行此过程。

我使用jgraph实现了上述目标,但结果在外观上相当差。

非常感谢,

SPAP

1 个答案:

答案 0 :(得分:2)

不幸的是,没有干净的方法来做到这一点。您可以通过第一次绘制数据(在多重绘图中)然后制作“空”图以在事后添加更多键来实现类似的操作。

set boxwidth 0.75 absolute 
set style fill solid 1.00 border -1
set style data histogram
set style histogram rowstacked
set xtics 1000 nomirror
set ytics 100 nomirror
set mxtics 2
set mytics 2
set ytics 10
set yrange [0:120]
set ylabel "Total time"
set multiplot

#These might be helpful to keep all the "plots" aligned.
set lmargin at screen .2
set rmargin at screen .9
set tmargin at screen .9
set bmargin at screen .2

set key at first .5,screen .1 #could be "set key at screen 0.1,0.1"  You'll have to play around with it.

plot 'data' using 2 t "Idle", \
     '' using 3 t "User space", \
     '' using 4 :xtic(1) t "Kernel space"

unset xtics
unset xlabel
unset ytics
unset ylabel
unset title
unset border 
set xrange [GPVAL_X_MIN:GPVAL_X_MAX]

set key at first 1.5,screen .1 
plot NaN t "Idle (app2)" w boxes, \
     NaN t "User space (app2)" w boxes, \
     NaN t "Kernel space (app2)" w boxes

unset multiplot