【发布时间】:2019-09-30 06:25:40
【问题描述】:
我在 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
添加空格可以改变百分比:
但即使它适用于这个图表,它也会移动其他图表的百分比......:
我无法获得“干净”的图形。要么是百分比重叠,要么是因为值太大而超出范围,或者完全偏移了......
有没有办法根据值以及条形的大小等自动使所有这些移动?
【问题讨论】:
-
请显示相关代码并说明确切的问题或错误。另见How to create a Minimal, Complete, and Verifiable example。为按预期工作的东西添加代码和图片没有帮助,而且浪费时间和空间。
-
查看我的回答stackoverflow.com/a/40492423/2604213,了解如何构建直方图。关键是用
using获得盒子的顶部中心,然后用offset从那里移动:plot ... using ... with labels offset ...