在同一图中显示单条形图和堆积条形图

时间:2012-11-30 16:56:42

标签: gnuplot

我有一个这样的数据文件:

"Execution"  500
"Overhead 1" 200
"Overhead 2" 75

我正在尝试绘制此数据的直方图,将执行时间显示为单个条形图,但开销1 开销2 作为单个堆叠条形图。

这是我到目前为止所做的:

set terminal postscript eps 24
set output "wq_time_profile.eps"
set size 0.95,0.95
set boxwidth 1.0 relative    
set style fill solid 0.5 noborder   
set style data histogram 
set style histogram cluster gap 1  
set ylabel "Time (mins)"                                                                      
plot "wq_time_profile.dat" u 1 notitle, "" u 2 notitle, "" u 3 notitle

我无法理解如何将第2行和第3行显示为堆积条形图,同时在同一图中将第1行显示为独立条形图。这可能在gnuplot中吗?我正在使用gnuplot v4.2。谢谢!

编辑:修改了标题和问题,以澄清情节需要包含一个独立的条形图和一个叠加的条形图在同一个gat相同的情节

1 个答案:

答案 0 :(得分:2)

这似乎有效:

set style fill solid 0.5 noborder
set style histogram columnstacked
set style data histogram
set ylabel "Time (mins)"
plot "test.dat" u 2 notitle with histogram

如果您想要一个带有颜色标签的钥匙:

set style histogram columnstacked
set style data histogram
set style fill solid 0.5 noborder
set ylabel "Time (mins)"
plot "test.dat" u 2:key(1) with histogram

阅读完编辑并玩了一下之后,这仍然有可能,但我需要修改你的数据文件。 (我希望没关系):

"Execution"  500


"foo" NaN
"Overhead 1" 200
"Overhead 2" 75

现在的绘图脚本:

set style histogram columnstacked
set style data histogram
set style fill solid 0.5 noborder
set ylabel "Time (mins)"
plot for [i=0:1] "test.dat" index i u ($2):key(1) with histogram

这里有一堆细微之处。这对空白记录是一种为绘图时gnuplot创建单独“索引”的方法。第一个栏本身就是一个数据集。这就是问题,Gnuplot会将索引0的第一条记录与索引1的第一条记录进行匹配,并用相同的颜色绘制它们。那很难看。因此,我们需要在index = 1数据集中插入一个假记录,该记录不会产生任何绘图,但会占用一种颜色。这就是"foo" NaN行的目的。我还需要修改plot行来绘制两个索引。使用规范需要从2:key(1)更改为($2):key(1),因为两种表单处理缺失数据的方式略有不同。

相关问题