gnuplot中的水平条形图 [英] Horizontal bar chart in gnuplot
问题描述
在谷歌搜索水平gnuplot条形图"时,我可以找到的第一个结果
重置$ heights<<排爆爸爸181妈妈170儿子100女儿60排爆设置yrange [0:*]#从零开始,从数据中找到最大值设置boxwidth 0.5#使用固定宽度的盒子取消键#关闭所有标题设置样式填充纯色#纯色框设置颜色podo设置Xtic旋转90比例0未定论设置y2tics旋转90使用0:2:($ 0 + 1):xtic(1)使用框lc变量绘制'$ heights'
有更好的方法吗?
您所指的链接来自大约.2009年.gnuplot从那时起就发展起来了.按照@Christoph的建议,请选中 help boxxyerror
.
代码:
###水平条形图重置会话$ Data<<排爆爸爸181妈妈170儿子100女儿60排爆设置yrange [0:*]#从零开始,从数据中找到最大值设置样式填充纯色#纯色框取消键#关闭所有标题myBoxWidth = 0.8设置偏移量0,0,0.5-myBoxWidth/2.,0.5使用2:0:(0):2:($ 0-myBoxWidth/2.):($ 0 + myBoxWidth/2.):(($ 0 + 1):ytic(1)和boxxyerror lc var绘制$ Data###代码结尾
结果:
添加:
做什么
2:0:(0):2:($ 0-myBoxWidth/2.):($ 0 + myBoxWidth/2.):($ 0 + 1):ytic(1)
是什么意思?
好吧,它看起来比实际要复杂.选中 help boxxyerror
.从手册中:
6列:
x y xlow xhigh ylow yhigh
所以,总共:
- x从第2列获取值,但此处不那么相关,因为我们将使用xyerror框
- y接受伪列
0
,它是从零开始的行号,请检查help伪列
,但在这里也不太相关 - xlow
(0)
表示固定值为零 - 第2列的xhigh值
- ylow
($ 0-myBoxWidth/2.)
,行号减去boxwidth的一半 - yhigh
($ 0 + myBoxWidth/2.)
,行号加上框宽的一半 -
($ 0 + 1)
与... lc lc
:颜色取决于行号,从1开始 -
ytic(1)
:第1列作为ytic标签
由于某些原因(我不知道),gnuplot似乎仍然没有方便的水平直方图绘制样式,但是至少它提供了这种 boxxyerror
解决方法.
When Googling "horizontal gnuplot bar chart", the first result I could find http://www.phyast.pitt.edu/~zov1/gnuplot/html/histogram.html suggests rotating (!) the final bar chart which seems rather baroque. Nonetheless I tried the approach but the labels are cut off.
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
Is there a better approach?
The link you are referring to is from approx. 2009. gnuplot has developed since then. As @Christoph suggested, check help boxxyerror
.
Code:
### 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
Result:
Addition:
what does
2:0:(0):2:($0-myBoxWidth/2.):($0+myBoxWidth/2.):($0+1):ytic(1)
mean?
Well, it looks more complicated than it is. Check help boxxyerror
. From the manual:
6 columns:
x y xlow xhigh ylow yhigh
So, altogether:
- x take value from column 2, but not so relevant here since we will use the xyerror box
- y take pseudocolumn
0
which is line number starting from zero, checkhelp pseudocolumns
, but not so relevant here as well - xlow
(0)
means fixed value of zero - xhigh value from column 2
- ylow
($0-myBoxWidth/2.)
, line number minus half of the boxwidth - yhigh
($0+myBoxWidth/2.)
, line number plus half of the boxwidth ($0+1)
together with... lc var
: color depending on line number starting from 1ytic(1)
: column 1 as ytic label
For some reason (which I don't know) gnuplot still doesn't seem to have a convenient horizontal histogram plotting style, but at least it offers this boxxyerror
workaround.
这篇关于gnuplot中的水平条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!