【问题标题】:How to draw a histogram with broken x-axis and string labels?如何绘制带有损坏的 x 轴和字符串标签的直方图?
【发布时间】:2015-06-01 16:08:55
【问题描述】:

我正在尝试绘制 x 轴损坏的直方图。我从这个post 学到了基本的解决方案。

但是,我的直方图的 x 轴基于字符串,而不是数字。是这样的:

set terminal pdf
set output "test-bar.pdf"
set boxwidth 1.0 absolute
set style fill solid 1 border 0
set datafile separator ','
set style data histograms
set xtics nomirror rotate by -45
set ylabel 'Normalized Overhead (%)'
set grid ytics
set yrange [0:10]
plot 'test-bar.csv' using 2:xtic(1) lc rgb "#1E90FF"  title ''

数据是这样列出的:

expand , 8.63390441828
cut , 6.84657194596
sync , 6.03615235627
fold , 4.22117995557
nl , 3.54228486647
truncate , 2.66222961714
tr , 2.38357169059
stty , 2.28166797757
users , 2.04211869831
factor , 1.81517270821
tac , 1.790947574
uniq , 1.78799489138
mv , 1.75054704603
mktemp , 1.72228202368
dircolors , 1.6974169738

现在剧情是这样的:

如果我想利用broken axis 功能,比如在sttyusers 之间插入中断,我该怎么做?

我够清楚了吗?谢谢。

【问题讨论】:

    标签: gnuplot histogram


    【解决方案1】:

    虽然您使用数据文件中的 xtic 标签,但 xtics 被放置在整数 x 值处,从 0 开始。现在,您不能在绘制直方图时直接设置任意 x 值。您必须使用newhistogram at ... 将直方图的第二部分进一步向右移动:

    split = 8
    plot 'test-bar.csv' using 2:xtic(1) every ::0::(split-1) lt 1,\
         newhistogram at split+1,\
         '' using 2:xtic(1) every ::split lt 1
    

    如您链接的帖子中所示,完成了上下边框以及断轴标志的绘制。一个可能的完整脚本可能是

    set terminal pdf
    set output "test-bar.pdf"
    set boxwidth 0.5 absolute
    set style fill solid 1 border 0
    set datafile separator ','
    set style data histograms
    set style histogram rowstacked
    set xtics nomirror rotate by -45
    set ylabel 'Normalized Overhead (%)'
    set grid ytics
    set yrange [0:10]
    
    unset key
    set border 2+8
    set linetype 1 lc rgb "#1E90FF"
    
    split=8
    dx = 0.125
    dy = 0.03
    
    do for [i=0:1] {
      set arrow 1+i from graph 0,graph i to first split-dx,graph i lt -1 nohead
      set arrow 3+i from first split+dx,graph i to graph 1,graph i lt -1 nohead
    
      set arrow 5+i from first split-2*dx,graph i-dy to first split,graph i+dy lt -1 nohead
      set arrow 7+i from first split,graph i-dy to split+2*dx,graph i+dy lt -1 nohead
    }
    
    plot 'test-bar.csv' using 2:xtic(1) every ::0::(split-1) lt 1,\
         newhistogram at split+1,\
         '' using 2:xtic(1) every ::split lt 1
    

    或者,如果您不添加或堆叠更多列,您可以使用boxes 绘图样式,它允许您使用正常的数值轴。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-24
      • 2015-10-16
      • 1970-01-01
      • 1970-01-01
      • 2018-05-25
      • 1970-01-01
      相关资源
      最近更新 更多