gnuplot 中的水平条形图
Horizontal bar chart in gnuplot
当谷歌搜索“水平 gnuplot 条形图”时,我能找到的第一个结果 http://www.phyast.pitt.edu/~zov1/gnuplot/html/histogram.html 建议旋转 (!) 最后的条形图,这看起来很巴洛克。尽管如此,我尝试了这种方法,但标签被切断了。
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:([=10=]+1):xtic(1) with boxes lc variable
有没有更好的方法?
您所指的 link 来自大约。 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:([=10=]-myBoxWidth/2.):([=10=]+myBoxWidth/2.):([=10=]+1):ytic(1) with boxxyerror lc var
### end of code
结果:
加法:
what does
2:0:(0):2:([=12=]-myBoxWidth/2.):([=12=]+myBoxWidth/2.):([=12=]+1):ytic(1)
mean?
嗯,看起来比实际要复杂。检查 help boxxyerror
。来自手册:
6 columns: x y xlow xhigh ylow yhigh
所以,一共:
- x 从第 2 列取值,但在这里不那么相关,因为我们将使用 xyerror 框
- y 取伪列
0
,它是从零开始的行号,检查help pseudocolumns
,但这里也不太相关
- xlow
(0)
表示固定值为零
- x 第 2 列的最高值
- ylow
([=18=]-myBoxWidth/2.)
, 行号减去一半框宽
- yhigh
([=19=]+myBoxWidth/2.)
, 行号加半框宽
([=20=]+1)
连同... lc var
:颜色取决于从1 开始的行号
ytic(1)
:第 1 列作为 ytic 标签
出于某种原因(我不知道)gnuplot 似乎仍然没有方便的水平直方图绘图样式,但至少它提供了这种 boxxyerror
解决方法。
当谷歌搜索“水平 gnuplot 条形图”时,我能找到的第一个结果 http://www.phyast.pitt.edu/~zov1/gnuplot/html/histogram.html 建议旋转 (!) 最后的条形图,这看起来很巴洛克。尽管如此,我尝试了这种方法,但标签被切断了。
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:([=10=]+1):xtic(1) with boxes lc variable
有没有更好的方法?
您所指的 link 来自大约。 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:([=10=]-myBoxWidth/2.):([=10=]+myBoxWidth/2.):([=10=]+1):ytic(1) with boxxyerror lc var
### end of code
结果:
加法:
what does
2:0:(0):2:([=12=]-myBoxWidth/2.):([=12=]+myBoxWidth/2.):([=12=]+1):ytic(1)
mean?
嗯,看起来比实际要复杂。检查 help boxxyerror
。来自手册:
6 columns:
x y xlow xhigh ylow yhigh
所以,一共:
- x 从第 2 列取值,但在这里不那么相关,因为我们将使用 xyerror 框
- y 取伪列
0
,它是从零开始的行号,检查help pseudocolumns
,但这里也不太相关 - xlow
(0)
表示固定值为零 - x 第 2 列的最高值
- ylow
([=18=]-myBoxWidth/2.)
, 行号减去一半框宽 - yhigh
([=19=]+myBoxWidth/2.)
, 行号加半框宽 ([=20=]+1)
连同... lc var
:颜色取决于从1 开始的行号
ytic(1)
:第 1 列作为 ytic 标签
出于某种原因(我不知道)gnuplot 似乎仍然没有方便的水平直方图绘图样式,但至少它提供了这种 boxxyerror
解决方法。