【问题标题】:Gnuplot: Multiple histograms with different keysGnuplot:具有不同键的多个直方图
【发布时间】:2012-06-12 14:55:41
【问题描述】:

我想使用 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"

我得到的结果是这样的:

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

我的目的是创建一个脚本来生成数据文件和 gnuplot 脚本来自动化这个过程。

我已经使用 jgraph 实现了上述效果,但在外观方面效果很差。

非常感谢,

啪啪啪

【问题讨论】:

    标签: plot gnuplot histogram


    【解决方案1】:

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

    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
    

    【讨论】:

    • 谢谢,成功了!这正是我一直在寻找的。太糟糕了,它不是内置功能。
    • @Spap -- 是的,gnuplot 有一些我偶尔会尝试解决的“单例”(键和调色板)是我能想到的两个头。
    猜你喜欢
    • 2017-08-25
    • 1970-01-01
    • 2018-10-24
    • 2014-08-04
    • 2012-07-24
    • 1970-01-01
    • 1970-01-01
    • 2017-08-28
    • 1970-01-01
    相关资源
    最近更新 更多