我有多个gnuplot文件可以在不同的时间范围内生成相同的图形。所以我有一个渲染全部,一个只渲染过去48小时,一个渲染特定月份。
现在我的问题是,有没有办法重用大多数设置(因为它们大多数相同)并且只更改绘图范围和输出文件的值?
这些是例如48小时设置:
set xlabel "Date (UTC)"
set ylabel "Size (Gibibytes)"
set title sprintf("Storagespace used and available (Generated: %s)", date)
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%Y\n%m-%d\n%H:%M"
set xtics rotate
set terminal svg size 1280,720
set output "/var/www/sizes/sizes-graph-48h.svg"
set datafile separator " "
set autoscale xfix
set key below
set grid xtics ytics
FACTOR=1024*1024
plot "< tail -48 /home/fabian/sizes" using 1:($3/FACTOR) title 'Used by 4th/Aufnahme' with lines lc rgb "#008080", \
"" using 1:($2/FACTOR) title 'Used by 3rd/Aufnahme' with lines lc rgb "#65000B", \
"" using 1:($5/FACTOR) title 'Available on 4th' with lines lc rgb "blue", \
"" using 1:($4/FACTOR) title 'Available on 3rd' with lines lc rgb "red", \
"" using 1:(($5+$3*17/20)/FACTOR) title 'Est. max. available on 4th' with lines lc rgb "#0F52BA", \
"" using 1:(($4+$2*17/20)/FACTOR) title 'Est. max. available on 3th' with lines lc rgb "#E62020", \
20 notitle
以下是48小时设置与特定月份设置之间的差异:
9c9
< set output "/var/www/sizes/sizes-graph-48h.svg"
---
> set output sprintf("/var/www/sizes/sizes-graph-%s.svg", month)
15c15
< plot "< tail -48 /home/fabian/sizes" using 1:($3/FACTOR) title 'Used by 4th/Aufnahme' with lines lc rgb "#008080", \
---
> plot sprintf("< grep \"%s*\" /home/fabian/sizes", month) using 1:($3/FACTOR) title 'Used by 4th/Aufnahme' with lines lc rgb "#008080", \
如您所见,除了输出文件(可以将month
设置为48h
)和绘图范围参数之外,它们是相同的。这里要完成的是48小时设置与“整体”设置的区别:
9c9
< set output "/var/www/sizes/sizes-graph-48h.svg"
---
> set output "/var/www/sizes/sizes-graph.svg"
15c15
< plot "< tail -48 /home/fabian/sizes" using 1:($3/FACTOR) title 'Used by 4th/Aufnahme' with lines lc rgb "#008080", \
---
> plot "/home/fabian/sizes" using 1:($3/FACTOR) title 'Used by 4th/Aufnahme' with lines lc rgb "#008080", \
好的,这里的输出文件最后没有破折号,但我可以使用set output sprintf("/var/www/sizes/sizes-graph%s.svg", range)
之类的range
之前的month
,但前面有一个破折号。
但主要的问题是:一旦我使用tail,在另一种情况下我使用grep,在最后一种情况下我不使用(尽管我可以使用匹配所有行的grep)。那么有没有办法说出类似gnuplot settings.gnuplot plotsource="< tail -48 /home/fabian/sizes"
的内容?
费边
答案 0 :(得分:1)
取决于事物的相似程度,您可以使用gnuplot的call
命令。否则,您可以将单独的组件拆分为文件和load
所需的组件。 (call
与load
类似,只是它接受其他参数。)
答案 1 :(得分:1)
以下是如何将脚本调用减少为只有一个参数传递给脚本。这在一个gnuplot脚本中隐藏了更多细节:
set xlabel "Date (UTC)"
set ylabel "Size (Gibibytes)"
set title sprintf("Storagespace used and available (Generated: %s)", \
"`date -u +"%Y-%m-%d %H:%M:%S (%Z)"`")
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%Y\n%m-%d\n%H:%M"
set xtics rotate
set terminal svg size 1280,720
if (exists('month')) {
source = sprintf('< grep "%s*" /home/fabian/sizes', month)
name = month
} else {
if (!exists('hours')) { hours = 48 }
name = sprintf('%dh', hours)
source = sprintf('< tail -%d /home/fabian/sizes', hours)
}
set output sprintf("/var/www/sizes/sizes-graph-%s.svg", name)
set datafile separator " "
set autoscale xfix
set key below
set grid xtics ytics
FACTOR=1024*1024
plot source using 1:($3/FACTOR) title 'Used by 4th/Aufnahme' with lines lc rgb "#008080", \
"" using 1:($2/FACTOR) title 'Used by 3rd/Aufnahme' with lines lc rgb "#65000B", \
"" using 1:($5/FACTOR) title 'Available on 4th' with lines lc rgb "blue", \
"" using 1:($4/FACTOR) title 'Available on 3rd' with lines lc rgb "red", \
"" using 1:(($5+$3*17/20)/FACTOR) title 'Est. max. available on 4th' with lines lc rgb "#0F52BA", \
"" using 1:(($4+$2*17/20)/FACTOR) title 'Est. max. available on 3th' with lines lc rgb "#E62020", \
20 notitle
现在您可以使用
调用脚本gnuplot -e "month='sep'" /home/fabian/sizetable-base.gnuplot
或
gnuplot -e "hours=48" /home/fabian/sizetable-base.gnuplot
如果在未设置hours
或month
的情况下调用,也是默认值。
答案 2 :(得分:0)
我发现一个解决方案是使用bash。标题已经有date
参数,我使用bash自动生成。所以我创建了一个基本的gnuplot模板:
set xlabel "Date (UTC)"
set ylabel "Size (Gibibytes)"
set title sprintf("Storagespace used and available (Generated: %s)", date)
set xdata time
set timefmt "%Y-%m-%d %H:%M:%S"
set format x "%Y\n%m-%d\n%H:%M"
set xtics rotate
set terminal svg size 1280,720
set output sprintf("/var/www/sizes/sizes-graph-%s.svg", type)
set datafile separator " "
set autoscale xfix
set key below
set grid xtics ytics
FACTOR=1024*1024
plot source using 1:($3/FACTOR) title 'Used by 4th/Aufnahme' with lines lc rgb "#008080", \
"" using 1:($2/FACTOR) title 'Used by 3rd/Aufnahme' with lines lc rgb "#65000B", \
"" using 1:($5/FACTOR) title 'Available on 4th' with lines lc rgb "blue", \
"" using 1:($4/FACTOR) title 'Available on 3rd' with lines lc rgb "red", \
"" using 1:(($5+$3*17/20)/FACTOR) title 'Est. max. available on 4th' with lines lc rgb "#0F52BA", \
"" using 1:(($4+$2*17/20)/FACTOR) title 'Est. max. available on 3th' with lines lc rgb "#E62020", \
20 notitle
这需要3个参数:date
,type
和source
。使用最后48个条目(=小时)的bash脚本如下所示:
gnuplot -e "date='`date -u +"%Y-%m-%d %H:%M:%S (%Z)"`'" -e "type='48h'" -e "source='< tail -48 /home/fabian/sizes'" /home/fabian/sizetable-base.gnuplot