1

我有多个 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", \

如您所见,除了输出文件(可以设置month48h)和绘图范围参数外,它们是相同的。要完整,这里是 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)where rangeis like monthbefore 但带有前导破折号的东西。

但主要问题是:一旦我使用 tail,在另一种情况下我使用 grep,在最后一种情况下我都不使用(尽管我可以使用匹配所有行的 grep)。那么有没有办法说类似的话gnuplot settings.gnuplot plotsource="< tail -48 /home/fabian/sizes"

费边

4

3 回答 3

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

于 2013-10-22T11:53:13.493 回答
1

根据事物的相似程度,您可以使用 gnuplot 的call命令。否则,您可以将单独的组件分解为文件和load您需要的组件。(call就像load它接受额外的参数一样。)

于 2013-10-20T15:43:49.257 回答
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 个参数datetypesource。使用最后 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
于 2013-10-22T10:45:07.477 回答