views:

185

answers:

3

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!

+8  A: 

ListPlot[Transpose[{x, y}]]

ragfield
And it is even cleaner if you use the Transpose short notation: {x,y} ESC tr ESC
gdelfino
A: 

ListPlot[{x,y}]

EDIT: @Davorak: it certainly will. If OP wants 'y against x' then

ListPlot[y]

would suffice. Either way, I don't understand the complicated answers to a very simple question. But then, I don't understand a lot of the questions on SO.

High Performance Mark
I do not think so. This will plot two separate trends.
Davorak
ListPlot[y] only works if x happens to be {1,2,3,...}
dreeves
+5  A: 

I do not hink Timo's solution is standard. Here are two methods that I have often seen used.

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

outputs:

{{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.

Davorak
You are correct, I was tired :-(.
Timo
Justice has been served! ;-)
Timo