Mak*_*kmy 2 linux bash gnuplot
我需要生成一个gnuplot直方图,以便查看我的群集每月的CPU和RAM演变:
我想从此文件生成直方图:
July 2018,19%,46%
August 2018,20%,45%
September 2018,20%,41%
October 2018,21%,39%
November 2018,21%,39%
December 2018,21%,41%
January 2019,25%,46%
February 2019,27%,50%
为此,这是我的代码:
set title " CLUSTER 1 "
set terminal png truecolor size 960, 720
set output " cluster1.png"
set key below
set grid
set style data histograms
set style fill solid 1.00 border -1
set datafile separator ","
plot 'cluster.txt' using 2:xtic(1) title " CPU consumption (%) ", '' using 3 title " RAM consumption (%)"
但是如您所见,我的x轴有问题。日期彼此重叠,我无法更改...您能告诉我如何更改吗?
而且,您能告诉我如何将百分比放在直方图栏上方吗?
最后,我想要一个像这样的直方图:
![[2]](https://i.stack.imgur.com/dfgwF.png)
要将单词包装在类别中,可以在必要时用三元函数替换换行符:
f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w)
如果标签的长度超过10个字符,则将空格替换为“ \ n”。
要在Y轴上添加百分号,请设置y格式,如下所示:
set format y "%g%%"
要添加标签,请使用带有标签的图:
'' using 0:($2+1):(sprintf("%g%%",$2)) with labels notitle, \
'' using 0:($3+1):(sprintf("     %g%%",$3)) with labels notitle
您可能需要更改图的底边距以适合两行标签和关键点:
set bmargin at screen 0.1
因此,脚本如下所示:
f(w) = (strlen(w) > 10 ? word(w, 1) . "\n" . word(w, 2) : w)
set title "CLUSTER 1"
set terminal png truecolor size 960, 720
set output "cluster1.png"
set bmargin at screen 0.1
set key below
set grid
set style data histograms
set style fill solid 1.00 border -1
set boxwidth 0.7 relative
set yrange [0:]
set format y "%g%%"
set datafile separator ","
plot 'cluster.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