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?
Asked
Active
Viewed 280 times
1 Answers
2
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);}

Andrew
- 873
- 4
- 10
-
I have problems to make that work for lists. If I replace in {ploth(i=0, 200, [i, sin(i*3*Pi/200), i, cos(i*3*Pi/200)], "Parametric|no_Lines", 200);} one argument by mylist[i], then i get in trouble, because the list only accepts integer values – klirk Jan 13 '18 at 11:59
-
1PARI's plotting features are fairly basic - they are ok to do a quick initial plot but at some point it gets easier to export data into another tool with more capabilities. And yes when working with lists you need to do something like \1 to round the index to an integer. – Andrew Jan 13 '18 at 15:39