带有标题的Gnu绘图水平条形图 [英] Gnu Plot Horizontal Bar Graph with titles
问题描述
我正在寻找使用gnuplot创建条形图,该条形图与以下内容非常相似.我有技术"的原始数据:-0.72%"等等.
I'm looking to create a bar graph using gnuplot that looks very similar to the following. I have the raw data for the "Technology": "-0.72%" and so on in array.
我已经掌握了水平绘制图形的方法,但是调整并确保最终图像看起来似乎超出了我.任何指针都值得赞赏吗?
I have gotten it up to horizontally drawing the graphs, but adjusting and making sure that the final image looks like seems to be beyond me. Any pointers are appreciated ?
推荐答案
以下是使用绘图样式 boxxyerror
的建议(请选中 help boxxyerror
).使用三元运算符根据第2列的值选择颜色(请检查 help三元
).使用带有标签的打印样式将值绘制为数字,数字的对齐方式为负数为
right
,正数为 left
被过滤"使用三元运算符.
Here is a sugggestion using the plotting style boxxyerror
(check help boxxyerror
).
The color is chosen depending on the column 2 values using the ternary operator (check help ternary
).
The values are plotted as numbers using plotting style with labels
and the alignment of the numbers which is either right
for negative numbers and left
for positive numbers is "filtered" using the ternary operator.
更改了代码,以便显示正号(和零)的 +
符号,此外,是否具有%
-是否登录您的数据(在绘制标签时会添加%
).
Code changed such that it will show +
-sign for positive numbers (and zero), and furthermore it will not matter whether your have the %
-sign in your data or not (it will add %
when plotting the label).
代码:
### Horizontal bar graph
reset session
$Data <<EOD
A -3.5%
B -1.3%
C 0.0%
D 1.5%
E 2.4%
F 5.3%
G 7.3%
EOD
myColor(col) = column(col)<0 ? 0xff0000 : column(col)==0 ? 0xcccccc : 0x00ff00
BoxWidth = 0.8
BoxYLow(i) = i - BoxWidth/2.
BoxYHigh(i) = i + BoxWidth/2.
set style fill transparent solid 0.3
set yrange [:] reverse
unset key
set offsets 1,1,0.5,0.5
plot $Data u (0):0:(0):2:(BoxYLow($0)):(BoxYHigh($0)):(myColor(2)):ytic(1) w boxxy lc rgb var, \
'' u ($2<0?$2:NaN) :0:(sprintf("%+g%",$2)) w labels offset -0.5,0 right, \
'' u ($2>=0?$2:NaN):0:(sprintf("%+g%",$2)) w labels offset 0.5,0 left
### end of code
结果:
这篇关于带有标题的Gnu绘图水平条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!