【问题标题】:Incorrect position and size of percentages in Gnu PlotGnu Plot中百分比的位置和大小不正确
【发布时间】: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

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

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

我无法获得“干净”的图形。要么是百分比重叠,要么是因为值太大而超出范围,或者完全偏移了......

另一个例子:

有没有办法根据值以及条形的大小等自动使所有这些移动?

【问题讨论】:

标签: linux bash gnuplot cgi


【解决方案1】:

您可以尝试另一种机制,使用 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

【讨论】:

    猜你喜欢
    • 2018-11-20
    • 2010-12-07
    • 2016-07-11
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多