2

How to plot a discrete dataset with 3 or more columns? MWE is as follows:

/* Required essentially to create the data set */
eqn1: 4 - x^2 - 4*y^2$
eqn2: y^2 - x^2 + 1$
sol: rk([eqn1,eqn2],[x,y],[-1.25, 0.75],[t,0,4,0.2])$

/* My current workaround to plot (x vs t) and (y vs t) */
n : length(sol)$
/* Select the ith column and create separate lists */
tseries : makelist(sol[i][1], i, 1, n)$ 
xseries:  makelist(sol[i][2], i, 1, n)$ 
yseries:  makelist(sol[i][3], i, 1, n)$ 

plot2d([
    [discrete, tseries, xseries],
    [discrete, tseries, yseries]
], [legend,"x","y"] ,[xlabel,"t"], [ylabel,"x, y"],[style, 
[linespoints,2,2]],
[gnuplot_preamble,"set key box width 2 spacing 1.3 top left"])$

Is there a better solution to plot without creating the tseries, xseries and yseries lists?

2
  • 1
    Well, it seems like [sol[k][2], sol[k][3]] are the x and y coordinates corresponding to sol[k][1]. So maybe plot2d([discrete, map (rest, sol)]) is enough. Commented Dec 11, 2018 at 17:38
  • @RobertDodier: This doesn't produce the same plots. The command map(rest,sol) produces the 2nd and 3rd column of the original data set. So I am guessing a variation of the above command will give the (1st and 2nd column) and (1st and 3rd column). Commented Dec 12, 2018 at 8:48

1 Answer 1

2

OK, based on your comment I see what is the goal. Your solution can be made a little more brief although not a lot. Anyway, map(lambda([txy], [txy[1], txy[2]]), sol) produces the list of [t, x] points and map(lambda([txy], [txy[1], txy[3]]), sol) produces the list of [t, y] points. So with sol as given above, I find that

plot2d ([[discrete, map(lambda([txy], [txy[1], txy[2]]), sol)],
         [discrete, map(lambda([txy], [txy[1], txy[3]]), sol)]]);

has the desired output (omitting the plotting options for clarity).

Sign up to request clarification or add additional context in comments.

Comments

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.