gnuplot rowstacked 直方图:如何将总和放在条形图上方
gnuplot rowstacked histogram: how to put sum above bars
此问题与gnuplot histogram: How to put values on top of bars有关。
我有一个数据文件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;
现在我想将第 2 列和第 3 列的 总和 放在条形上方。显而易见的解决方案
plot newhistogram 'foo', 'file.dat' u 2:xtic(1) t col, '' u 3 t col, \
'' u ([=12=]-1):(++0.2):(+) notitle w labels font "Arial,8";
将标签放在正确的位置,但计算的总和是错误的。也就是说,在 ([=14=]-1):(++0.2):(+)
中,第二个
的计算结果似乎为零。
这里出了什么问题,我该如何解决?
您必须给出一个明确的字符串作为标签:
plot newhistogram 'foo', 'file.dat' u 2:xtic(1) t col, '' u 3 t col, \
'' u ([=10=]-1):(+):(sprintf('%.1f', +)) notitle w labels offset 0,1 font "Arial,8"
作为其他改进,我会使用 offset
选项,它允许您以字符单位给出位移,这不依赖于 yrange。
(旁注:如果使用列中的值,则可以跳过标签的显式格式设置,如 using 1:2:2 with labels
,但通常应使用 sprintf
来格式化标签标签)
此问题与gnuplot histogram: How to put values on top of bars有关。
我有一个数据文件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;
现在我想将第 2 列和第 3 列的 总和 放在条形上方。显而易见的解决方案
plot newhistogram 'foo', 'file.dat' u 2:xtic(1) t col, '' u 3 t col, \
'' u ([=12=]-1):(++0.2):(+) notitle w labels font "Arial,8";
将标签放在正确的位置,但计算的总和是错误的。也就是说,在 ([=14=]-1):(++0.2):(+)
中,第二个 的计算结果似乎为零。
这里出了什么问题,我该如何解决?
您必须给出一个明确的字符串作为标签:
plot newhistogram 'foo', 'file.dat' u 2:xtic(1) t col, '' u 3 t col, \
'' u ([=10=]-1):(+):(sprintf('%.1f', +)) notitle w labels offset 0,1 font "Arial,8"
作为其他改进,我会使用 offset
选项,它允许您以字符单位给出位移,这不依赖于 yrange。
(旁注:如果使用列中的值,则可以跳过标签的显式格式设置,如 using 1:2:2 with labels
,但通常应使用 sprintf
来格式化标签标签)