gnuplot 中的水平条形图

亨德利

当谷歌搜索“水平 gnuplot 条形图”时,我能找到的第一个结果http://www.phyast.pitt.edu/~zov1/gnuplot/html/histogram.html建议旋转(!)最终的条形图,这看起来相当巴洛克. 尽管如此,我尝试了这种方法,但标签被切断了。

第一次尝试使用 gnuplot 5.2 中的水平条形图

reset
$heights << EOD
dad                     181
mom                     170
son                     100
daughter        60
EOD

set yrange [0:*]      # start at zero, find max from the data
set boxwidth 0.5      # use a fixed width for boxes
unset key             # turn off all titles
set style fill solid  # solid color boxes

set colors podo

set xtic rotate by 90 scale 0
unset ytics
set y2tics rotate by 90

plot '$heights' using 0:2:($0+1):xtic(1) with boxes lc variable

有没有更好的方法?

西奥兹

您所指的链接来自大约。2009. gnuplot 从那时起得到发展。正如@Christoph 建议的那样,检查help boxxyerror.

代码:

### horizontal bar graph
reset session

$Data << EOD
dad         181
mom         170
son         100
daughter     60
EOD

set yrange [0:*]      # start at zero, find max from the data
set style fill solid  # solid color boxes
unset key             # turn off all titles

myBoxWidth = 0.8
set offsets 0,0,0.5-myBoxWidth/2.,0.5

plot $Data using 2:0:(0):2:($0-myBoxWidth/2.):($0+myBoxWidth/2.):($0+1):ytic(1) with boxxyerror lc var
### end of code

结果:

在此处输入图片说明

添加:

是什么2:0:(0):2:($0-myBoxWidth/2.):($0+myBoxWidth/2.):($0+1):ytic(1)意思?

嗯,它看起来比它更复杂。检查help boxxyerror从手册:

6 列: x y xlow xhigh ylow yhigh

所以,总而言之:

  1. x 从第 2 列中取值,但这里不那么相关,因为我们将使用 xyerror 框
  2. y 取伪列0,它是从零开始的行号,检查help pseudocolumns,但在这里也不太相关
  3. xlow(0)表示固定值为零
  4. 第 2 列的 xhigh 值
  5. ylow ($0-myBoxWidth/2.), 行号减去 boxwidth 的一半
  6. yhigh ($0+myBoxWidth/2.),行号加上框宽的一半
  7. ($0+1)连同... lc var:颜色取决于从 1 开始的行号
  8. ytic(1): 第 1 列作为 ytic 标签

出于某种原因(我不知道),gnuplot 似乎仍然没有方便的水平直方图绘制样式,但至少它提供了这种boxxyerror解决方法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章