I have two (pairs of) lists which I want to plot. I know, that I can plot each separably, using the plothraw function. But how can I plot them in the same picture, such that I end up with two curves in different colours?
As a reference, the following is a way to plot the two data sets in two separate plots using plothraw
:
\\ As two separate plots using plothraw plothraw([0..200], apply(i->sin(i*3*Pi/200), [0..200]), 0); plothraw([0..200], apply(i->cos(i*3*Pi/200), [0..200]), 0);
First solution using ploth
:
{ploth(i=0, 200, [i, sin(i*3*Pi/200), i, cos(i*3*Pi/200)], "Parametric|no_Lines", 200);}
Second solution using low level functions, but I could not get color to work (apparently supported on X-windows, but not Windows):
{my(s=plothsizes());plotinit(0,s[1]-1,s[2]-1);} plotscale(0, 0, 200, -1, 1); plotcolor(0, 2); \\ blue plotrecthraw(0, [ [0..200], apply(i->sin(i*3*Pi/200), [0..200]) ], 0); plotcolor(0, 4); \\ red plotpoints(0, [0..200], apply(i->cos(i*3*Pi/200), [0..200])); plotdraw([0,0,0]); \\ draws window 0 at (0,0) plotkill(0); \\ frees memory of window 0
Probably the first solution is the easiest to work with (especially if you don't want everything in the same color). In the case that you have the data in 4 vectors, say vx
, vy
, ux
, uy
all of which are the same length #vx == #vy == #ux == #uy
then the correct form is:
\\ first 2 lines just create test vectors vx=[0..200]; vy=apply(i->sin(i*3*Pi/200), [0..200]); ux=[0..200]; uy=apply(i->cos(i*3*Pi/200), [0..200]); \\ the actual plot - the \1's just round to integer index {ploth(i=1, #vx, [vx[i\1], vy[i\1], ux[i\1], uy[i\1]], "Parametric|no_Lines", #vx);}