我正在尝试将曲线放在不同的文件上以使它们进入单个png 我使用以下代码:
set terminal png enhanced font arial 14 size 800,600
set key outside horizontal left
f(x) = a*x**b
b = 1
a = 10000
fit f(x) 'a.txt' via a,b
plot 'a.txt' with dots lc rgb"red" title ' ', \
f(x) with lines lc rgb"red" title sprintf('Curve Equation: f(x) = %.2f·x^{%.2f}', a, b )
f1(x) = c*exp(d*x)
d = -1
c = 10000
fit f1(x) 'b.txt' via c,d
plot 'b.txt' with dots lc rgb"red" title ' ', \
f1(x) with lines lc rgb"blue" title sprintf('Curve Equation: f1(x) = %.2f·e^{-.%.2f.x}', c, d )
replot
unset output
exit gnuplot;
此代码中可能缺少的内容。
答案 0 :(得分:1)
在写入文件时,使用replot
通常是一个糟糕的选择。
基本上你有两个选择:
在一个plot
命令中写下所有情节信息(为了清楚起见,我遗漏了fit
内容):
set terminal pngcairo enhanced font arial 14 size 800,600
set output 'output.png'
# do some fitting
set style data dots
set style function lines
plot 'a.txt' lc rgb "red" title ' ', \
f(x) lc rgb "red" title sprintf('Curve Equation: f(x) = %.2f·x^{%.2f}', a, b), \
'b.txt' lc rgb "red" title ' ', \
f1(x) lc rgb"blue" title sprintf('Curve Equation: f1(x) = %.2f·e^{-.%.2f.x}', c, d )
如果要分离两个绘图块,需要对不同的终端进行一些操作,除第一个绘图块外,请使用replot ...
,并且必须设置png
终端和输出仅在最后replot
之前直接归档:
set style data dots
set style function lines
set terminal unknown
# do fitting of f(x)
plot 'a.txt' lc rgb "red" title ' ', \
f(x) lc rgb "red" title sprintf('Curve Equation: f(x) = %.2f·x^{%.2f}', a, b)
# do fitting of f1(x)
set terminal pngcairo enhanced font arial 14 size 800,600
set output 'output.png'
replot 'b.txt' lc rgb "red" title ' ', \
f1(x) lc rgb"blue" title sprintf('Curve Equation: f1(x) = %.2f·e^{-.%.2f.x}', c, d )
unset output
对于要在脚本开头指定最终终端的情况,这是2的变体。您可以使用set terminal push
保存当前终端,稍后使用set terminal pop
:
set terminal pngcairo enhanced font arial 14 size 800,600
output_file = 'output.png'
set style data dots
set style function lines
set terminal push
set terminal unknown
# do fitting of f(x)
plot 'a.txt' lc rgb "red" title ' ', \
f(x) lc rgb "red" title sprintf('Curve Equation: f(x) = %.2f·x^{%.2f}', a, b)
# do fitting of f1(x)
set terminal pop
set output output_file
replot 'b.txt' lc rgb "red" title ' ', \
f1(x) lc rgb"blue" title sprintf('Curve Equation: f1(x) = %.2f·e^{-.%.2f.x}', c, d )
unset output