Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have two lists of values

xx = {0.1, 0.3, 0.35, 0.57, 0.88, 1.0}
yy = {1.2, 3.5, 4.5, 7.8, 9.0, 12.2}

I want to make a scatter plot (list plot) with xx as x axis and yy as y axis. The help document on ListPlot tells me I have to use

ListPlot[{{x1, y1}, {x2, y2}, ...}]

How do I create something like

ListPlot[{{0.1, 1.2}, {0.3, 3.5}, ...}]

from xx and yy? Thank you.

share|improve this question
1  
Change square brackets [...] to braces {...} in the definitions of xx and yy. Check the documentation for Transpose and/or Thread –  kguler Mar 23 '13 at 1:42
    
@kguler Thank you. –  Patrick Li Mar 23 '13 at 2:16
add comment

2 Answers 2

up vote 8 down vote accepted

First off, your syntax is incorrect; you need to use braces to define your lists:

xx = {0.1, 0.3, 0.35, 0.57, 0.88, 1.0};
yy = {1.2, 3.5, 4.5, 7.8, 9.0, 12.2};

You can then create a 2x6 matrix from xx and yy, and transpose it to get a 6x2 matrix of pairs, which is the correct format:

data = Transpose@{xx, yy};
ListPlot[data]

Mathematica graphics

share|improve this answer
    
Great, Thank you. BTW: why did you write Transpose@{xx, yy} instead of Transpose[{xx, yy}]? –  Patrick Li Mar 23 '13 at 2:15
    
@PatrickLi, because they mean exactly the same thing. Look up Prefix in the documentation center. –  RunnyKine Mar 23 '13 at 2:24
    
@RunnyKine Got it. Thank you. –  Patrick Li Mar 23 '13 at 2:27
add comment

If you have

xx = {0.1, 0.3, 0.35, 0.57, 0.88, 1.0}
yy = {1.2, 3.5, 4.5, 7.8, 9.0, 12.2}

you can do

Thread[{xx, yy}]

which gives

{{0.1, 1.2}, {0.3, 3.5}, {0.35, 4.5}, {0.57, 7.8}, {0.88, 9.}, {1., 
  12.2}}

and then

ListPlot[{{0.1`, 1.2`}, {0.3`, 3.5`}, {0.35`, 4.5`}, {0.57`, 
   7.8`}, {0.88`, 9.`}, {1.`, 12.2`}}]

enter image description here

So

ListPlot[Thread[{xx, yy}]]

is the answer.

Kind regards

share|improve this answer
    
Your answer is not wrong, and thank you for contributing. But, how is it different from the other, accepted answer? –  Oleksandr R. Apr 26 at 23:19
    
I used Thread instead of Transpose. So you are right, when you say, the result is exactly the same. It's just a little different solution. –  Gabriel Apr 26 at 23:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.