Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListPlot With Two Data Sets in Mathematica

Is there a cleaner way to do the following, assuming that I have a reason to keep the data sets independent?:

x = {1, 2, 3};
y = {1, 4, 9};

ListPlot[Partition[Riffle[x, y], 2]]

Thanks!

like image 627
Scott Avatar asked Nov 27 '22 23:11

Scott


1 Answers

I do not think Timo's solution is standard. Here are two methods, using Transpose or Thread, that I have often seen used.

x = {1, 2, 3};
y = {1, 4, 9};
Transpose[{x, y}]
Thread[{x, y}]

Output:

{{1, 1}, {2, 4}, {3, 9}}
{{1, 1}, {2, 4}, {3, 9}}

Both of these methods avoid explicitly referencing the length of your data which is plus in my book.

like image 161
Davorak Avatar answered Dec 04 '22 11:12

Davorak