gnuplot行堆积直方图:如何将总和放在小节上方 [英] gnuplot rowstacked histogram: how to put sum above bars

查看:112
本文介绍了gnuplot行堆积直方图:如何将总和放在小节上方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题与 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;

现在,我想在栏上方放置第2列和第3列的 sums .显而易见的解决方案

Now I want to place the sums of columns 2 and 3 above the bars. The obvious solution

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似乎求值为零.

puts the labels in the correct place, but the calculated sum is wrong. That is, in ($0-1):($2+$3+0.2):($2+$3), the second $2 appears to evaluate to zero.

这里出了什么问题,我该如何解决?

What's going wrong here and how do I fix it?

推荐答案

您必须给一个明确的字符串作为标签:

You must give an explicit string as label:

 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.

As other improvement, I would use the offset option which allows you to give an displacement in character units, which doesn't depend on the yrange.

(注意:如果使用了列中的值,则可以跳过标签的显式格式,例如using 1:2:2 with labels,但通常应该使用sprintf来格式化标签)

(Side note: if a value from a column is used, then one can skip the explicit formatting of the label, like using 1:2:2 with labels, but in general one should use sprintf to format the label)

这篇关于gnuplot行堆积直方图:如何将总和放在小节上方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆