在多个gnuplots设置之间共享相同的设置

在多个gnuplots设置之间共享相同的设置,gnuplot,Gnuplot,我有多个gnuplot文件来生成同一个图形,但在不同的时间范围内。所以我有一个渲染所有的,一个只渲染最后48小时,一个渲染特定月份 我现在的问题是,有没有办法重用大多数设置(因为它们基本相同),只更改打印范围和输出文件的值 例如,这些是48小时设置: set xlabel "Date (UTC)" set ylabel "Size (Gibibytes)" set title sprintf("Storagespace used and available (Generated: %s)", d

我有多个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
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", \
好的,这里的输出文件末尾没有破折号,但是我可以使用类似于
设置输出sprintf(“/var/www/size/size-graph%s.svg”,range)
的东西,其中
range
类似于之前的
月份,但带有前导破折号

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


Fabian

根据事情的相似程度,您可以使用gnuplot的
call
命令。否则,您可以将单独的组件分解为文件,然后加载所需的组件。(
call
load
类似,只是它接受额外的参数。)

好的,我找到的一个解决方案是使用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
gnuplot-e“date=”`date-u+%Y-%m-%d%H:%m:%S(%Z)“`'''-e“type='48h''-e”source=”
以下是如何减少脚本调用,使其仅具有一个要传递给脚本的参数。这在这个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


如果调用时未设置
小时数
月数

,这也是默认值,因为我已经在使用bash脚本设置参数,我可以为绘图源添加另一个参数(使用
-e
),而不是使用
调用
。而且,
load
不能替代一切,因为它不能替代相当大的
plot
命令。关于相似性:它们非常相似,你可以在差异中看到:21行中有2行需要更改。啊!我不知道你可以在文件中添加这样的逻辑。在我更新了我的gnuplot(Ubuntu安装仍然使用4.4)之后,我让它开始工作(尽管我不得不做一些调整,比如在没有指定任何参数的情况下生成包含所有数据的图形)。谢谢
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