Draw multiple plots in same plot with Maple

2.1k Views Asked by At

I have a procedure in Maple

for Q in [2,4] do
  plot([Q, y, y=0..TR(Q)], thickness=2, linestyle=dash):
  textplot([Q, TR(Q), "Some text"], align={above, right})
end do;

but it prints 4 plots in each row (2 plots for each element in the list).

Instead, I want the 4 plots in the same plot. I know I can normally use display but I don't know how to do this when the plots are created inside a procedure.

Besides, the plot should also display some plots created outside of the procedure.

1

There are 1 best solutions below

0
On

You could try a few different methods. I wasn't sure what your function TR was, so just replace the 2 below with TR.

You could use a sequence:

plots:-display( [ seq( op( [ plot([Q, y, y=0..2], thickness=2, linestyle=dash), 
                             plots:-textplot([Q, 2, "Some text"], align={above, right}) ] ), 
                       Q in [2,4] ) ] );

Or as mentioned, you could build a list of plots and then display the list:

myplotarray := Array([]):
for Q in [2,4] do
    myplotarray := ArrayTools:-Append( myplotarray, plot([Q, y, y=0..2], thickness=2, linestyle=dash) ):
    myplotarray := ArrayTools:-Append( myplotarray, plots:-textplot([Q, 2, "Some text"], align={above, right}) ):
end do:
plots:-display( convert( myplotarray, list ) );