5
$\begingroup$

I just combined two lists using this method

molefrac = {1., 0.787402, 0.478927, 0.282592, 0.}
calibrationIndexOfRefraction = {1.440, 1.421, 1.395, 1.380, 1.351}
Partition[Riffle[molefrac, calibrationIndexOfRefraction], 2]
{{1., 1.44}, {0.787402, 1.421}, {0.478927, 1.395}, {0.282592, 1.38}, {0., 1.351}}

The purpose of this was to prepare the lists to be plotted using ListPlot. Is there some way to use ListPlot directly (or something more functional) to do this without going through all the extra steps?

$\endgroup$
4
  • $\begingroup$ What is molefrac ? And why do you have so many and btw unbalanced parenthesis in the 1st line? $\endgroup$ Apr 5, 2013 at 6:20
  • $\begingroup$ Why don't you use newList = Transpose[{molefrac, calibrationIndexOfRefraction}]. You will get the same result as above on a more straightforward way. This can be plotted easily with ListPlot[newList]. Or do I misunderstand your question? $\endgroup$
    – partial81
    Apr 5, 2013 at 6:33
  • $\begingroup$ @partial81 bill s beat us both (and kguler) to that answer. :-) $\endgroup$
    – Mr.Wizard
    Apr 5, 2013 at 6:35
  • $\begingroup$ Related, though with lists of different lengths: Elegantly pairing up mismatched lists. $\endgroup$ Apr 5, 2013 at 11:28

2 Answers 2

10
$\begingroup$

How about:

ListPlot[Transpose[{molefrac, calibrationIndexOfRefraction}]]

You can look at the help file for ListPlot to see the plotting options to make it look the way you wish.

$\endgroup$
1
  • 1
    $\begingroup$ +1 -- In the FrontEnd this is extremely concise: ListPlot[{molefrac, calibrationIndexOfRefraction}\[Transpose]] $\endgroup$
    – Mr.Wizard
    Apr 5, 2013 at 6:34
3
$\begingroup$

Another possible solution:

ListPlot[Thread[List[molefrac, calibrationIndexOfRefraction]]]

or

ListPlot[{molefrac, calibrationIndexOfRefraction}//Thread]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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