0

Currently, I can display the plot in maxima as follows:

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"])$

And save the plots with the command:

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"]
)$

How to display and save the plot in maxima simultaneously?

1 Answer 1

0

p2 takes a file name and the same arguments as 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"]);

It is a macro. First it substitutes file and L. splice(L)` is converted to an argument list. After the substitution the resulting expression is evaluated in the context of the caller.

You can use macroexpand to see the expression after substitution.

(%i1) a: 42 $
(%i2) macroexpand(p2(file, a, b));
(%o2)           (plot2d(a, b), plot2d(a, b, ['pdf_file, file]))
Sign up to request clarification or add additional context in comments.

1 Comment

Only changed the filename to "./trigplot.pdf" to save the plot in the current directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.