linux - Gnu Plot 中百分比的位置和大小不正确

标签 linux bash gnuplot cgi

我在 bash/html 中开发了一个 CGI,它允许我生成集群图。

举个例子: enter image description here

这是一个效果很好的图表。问题是对于某些图表,百分比重叠或偏离应有的位置太远。这是我的 GNUPLOT 代码:

f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w)

set title "TITLE"
set terminal png truecolor size 960, 720 background rgb "#eff1f0"
set output "/var/www/html/CLUSTER_NAME.png"
set bmargin at screen 0.1
set key top center
set grid
set style data histograms
set style fill solid 1.00 border -1
set boxwidth 0.7 relative
set yrange [*:*]
set format y "%g%%"
set datafile separator ","
plot 'test1.txt' using 2:xtic(f(stringcolumn(1))) title " CPU consumption (%) ", \
'' using 3 title " RAM consumption (%)", \
'' using 0:($2+1):(sprintf(" %g%%",$2)) with labels notitle, \
'' using 0:($3+1):(sprintf("     %g%%",$3)) with labels notitle

这是一个图表示例,由于百分比偏移太大而无法正常工作:

enter image description here

我可以通过更改代码中的这一行来更改它:

'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle

收件人:

'' using 0:($3+1):(sprintf("                               %g%%",$3)) with labels notitle

添加空格可以改变百分比:

enter image description here

但即使它适用于此图,它也会移动其他图的百分比...:

enter image description here

我无法获得“干净”的图形。要么百分比重叠,要么由于值太大而超出范围,或者它们完全移位....

另一个例子: enter image description here

有没有一种方法可以根据值以及条的大小等自行自动移动所有这些?

最佳答案

您可以尝试另一种机制,使用 plot for [i=2:3] ... 循环遍历 2 列值。您无需猜测要缩进的空格数,而是使用 column(0)+(i-2)*.25 估计栏的 x 位置(对于 i = 2 然后 3), 这是我通过反复试验得到的。

例如,使用函数 mytitle 获取 2 个标题(我的 gnuplot 对于数组来说太旧了):

mytitle(x) = (x==2?"cpu":"ram")
plot for [i=2:3] 'data' using i:xtic(stringcolumn(1)) title mytitle(i), \
     for [i=2:3] '' using (column(0)+(i-2)*.25):(column(i)+1):\
      (sprintf("%g%%",column(i))) with labels notitle

plots

关于linux - Gnu Plot 中百分比的位置和大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56109869/

相关文章:

linux - 在 Ubuntu 14.10 上配置 SQLCipher

linux - 如何在linux中模拟挂起的任务?

java - Linux Redhat .bash_profile 不起作用

arrays - 在 gnuplot 中声明两个数组并将它们相对于另一个进行绘制

linux - Bash - 将所有变量设为本地变量是个好主意吗?

仅当远程 TCP 服务器关闭时,Java NIO 客户端才会导致文件描述符泄漏

gnuplot - 在 gnuplot 中强制 z 范围 - pm3d

gnuplot - 计算后绘制 GNUplot 图

c++ - Linux 共享库中全局变量的单个拷贝

linux - 在 ubuntu 上运行 bash 主机脚本时遇到问题