我在 bash/html 中开发了一个 CGI,它允许我生成集群图。
这是一个效果很好的图表。问题是对于某些图表,百分比重叠或偏离应有的位置太远。这是我的 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
这是一个图表示例,由于百分比偏移太大而无法正常工作:
我可以通过更改代码中的这一行来更改它:
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
收件人:
'' using 0:($3+1):(sprintf(" %g%%",$3)) with labels notitle
添加空格可以改变百分比:
但即使它适用于此图,它也会移动其他图的百分比...:
我无法获得“干净”的图形。要么百分比重叠,要么由于值太大而超出范围,或者它们完全移位....
有没有一种方法可以根据值以及条的大小等自行自动移动所有这些?
最佳答案
您可以尝试另一种机制,使用 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
关于linux - Gnu Plot 中百分比的位置和大小不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56109869/