这个问题与gnuplot 直方图:如何将值放在条形顶部.
我有一个数据文件file.dat
:
x y1 y2
1 2 3
2 3 4
3 4 5
和 gnuplot:
set style data histogram;
set style histogram rowstacked;
plot newhistogram 'foo', 'file.dat' u 2:xtic(1) t col, '' u 3 t col;
现在我想放置sums条形上方的第 2 列和第 3 列。显而易见的解决方案
plot newhistogram 'foo', 'file.dat' u 2:xtic(1) t col, '' u 3 t col, \
'' u ($0-1):($2+$3+0.2):($2+$3) notitle w labels font "Arial,8";
将标签放在正确的位置,但计算出的总和是错误的。也就是说,在($0-1):($2+$3+0.2):($2+$3)
, 第二$2
似乎评估为零。
这里出了什么问题以及如何修复它?
您必须给出一个明确的字符串作为标签:
plot newhistogram 'foo', 'file.dat' u 2:xtic(1) t col, '' u 3 t col, \
'' u ($0-1):($2+$3):(sprintf('%.1f', $2+$3)) notitle w labels offset 0,1 font "Arial,8"
作为其他改进,我会使用offset
选项允许您以字符单位给出位移,该位移不依赖于 yrange。
(旁注:如果使用列中的值,则可以跳过标签的显式格式,例如using 1:2:2 with labels
,但一般来说应该使用sprintf
设置标签格式)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)