【问题标题】:Show single bar graph and a stacked bar graph in the same plot在同一图中显示单个条形图和堆叠条形图
【发布时间】:2012-11-30 16:56:41
【问题描述】:

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

"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。谢谢!

编辑:修改了标题和问题,以阐明该图需要在同一图中包含单个独立条形图和堆叠条形图

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    这似乎有效:

    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),因为这两种表单在处理缺失数据的方式上略有不同。

    【讨论】:

    • 感谢 mgilson 的回答!但是,我意识到我的问题不是很清楚。我现在对其进行了编辑以澄清它。我在这个问题中试图做的是在单个条形图中显示第 1 行,同时在堆叠条形图中显示第 2 行和第 3 行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-03
    • 2013-03-03
    • 2014-08-24
    • 2023-01-21
    • 2022-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多