当前,我可以按如下所示以最大值显示图:
f(x) := sin(x)$
g(x) := cos(x)$
plot2d([f(x), g(x)], [x,-5,5],[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[gnuplot_preamble,"set key box spacing 1.3 top right"])$
并使用以下命令保存绘图:
plot2d([f(x), g(x)], [x,-5,5],[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[pdf_file,"./trigplot.pdf"],
[gnuplot_preamble,"set key box spacing 1.3 top right"]
)$
如何同时以最大值显示和保存图?
答案 0 :(得分:0)
p2
具有一个文件名和与plot2d
相同的参数。
p2(file, [L])::=buildq([file, L],
(plot2d(splice(L)),
plot2d(splice(L), ['pdf_file, file])))$
f(x) := sin(x)$
g(x) := cos(x)$
p2("trigplot.pdf",
[f(x), g(x)], [x,-5,5],
[legend,"sin(x)","cos(x)"],
[xlabel,"x"],[ylabel,"y"],
[gnuplot_preamble,"set key box spacing 1.3 top right"]);
它是a macro。首先,它用file
和L
代替。 splice(L)`被转换为参数列表。替换后,将在调用者的上下文中评估结果表达式。
您可以使用macroexpand
来查看替换后的表达式。
(%i1) a: 42 $
(%i2) macroexpand(p2(file, a, b));
(%o2) (plot2d(a, b), plot2d(a, b, ['pdf_file, file]))