首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在多个gn上载设置之间共享相同的设置。

在多个gn上载设置之间共享相同的设置。
EN

Stack Overflow用户
提问于 2013-10-20 12:53:27
回答 3查看 126关注 0票数 1

我有多个gnu图文件来生成相同的图,但是在不同的时间范围内。所以,我有一个能渲染所有的,一个只呈现最后的48个小时,一个呈现一个特定的月份。

我现在的问题是,是否有一种方法可以重用大多数设置(因为它们大部分是相同的),并且只更改绘图范围和输出文件的值?

例如,这些是48小时的设置:

代码语言:javascript
复制
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小时设置与特定月份设置之间的差异:

代码语言:javascript
复制
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小时设置与“总体”设置的差异:

代码语言:javascript
复制
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,但有一个前导破折号。

但主要的问题是:一旦我使用尾,在另一种情况下,我使用grep,在最后一种情况下,我不使用(虽然我可以使用grep,它匹配所有行)。所以有没有办法说像gnuplot settings.gnuplot plotsource="< tail -48 /home/fabian/sizes"这样的话

法比安

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-10-22 11:53:13

下面是如何将脚本调用简化为只有一个要传递给脚本的参数。这会在这个gnuplot脚本中隐藏更多的细节:

代码语言:javascript
复制
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

现在,您可以使用

代码语言:javascript
复制
gnuplot -e "month='sep'" /home/fabian/sizetable-base.gnuplot

代码语言:javascript
复制
gnuplot -e "hours=48" /home/fabian/sizetable-base.gnuplot

如果在不设置hoursmonth的情况下调用,则这也是默认的。

票数 1
EN

Stack Overflow用户

发布于 2013-10-20 15:43:49

根据情况有多相似,您可以使用gnuplot的call命令。否则,您可以将独立的组件分解为文件,并对所需的组件进行load。(callload类似,只是它接受附加参数。)

票数 1
EN

Stack Overflow用户

发布于 2013-10-22 10:45:07

好的,我找到的一个解决办法是使用bash。标题的date参数已经存在,我使用bash自动生成该参数。因此,我创建了一个基本的gnuplot模板:

代码语言:javascript
复制
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个条目(= hours)的bash脚本如下所示:

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19477544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档