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 was searching in the list of questions here but I couldt find it. I have two vectors say x={0.1, 0.2, 0.3, 0.4, 0.5} and y={2, 3.5, 6, 7, 8}. I want to plot them with respect to each other using probably listplot or listlineplot. What is the easiest way of doing this?

thank you!

share|improve this question

closed as off-topic by Kuba, rasher, bobthechemist, Michael E2, RunnyKine May 27 at 0:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Kuba, rasher, bobthechemist, Michael E2, RunnyKine
If this question can be reworded to fit the rules in the help center, please edit the question.

    
what do you mean by "to plot them with respect to each other"? –  belisarius May 26 at 17:17
1  
@belisarius Probably Transpose. –  Kuba May 26 at 17:18
    
@belisarius they are x axis and y axis values. For example $(x_1,y_1)=(0.1,2)$ is the first point. –  Seyhmus Güngören May 26 at 17:33
    
@SeyhmusGüngören - Transpose[{x, y}] // ListPlot is all you need to do - gives the same result like the answer but is simpler. –  eldo May 26 at 17:54
1  
@SeyhmusGüngören - ListPlot[Transpose[{x, y}],Joined->True,GridLimes->Automatic, ... ] –  eldo May 26 at 18:15
show 4 more comments

2 Answers 2

up vote 4 down vote accepted

If I'm correct in understanding that you want a standard y versus x plot this will give the desired result:

ListPlot[Partition[Riffle[x, y], 2]]
share|improve this answer
add comment

As said in the comments and shown in the answer, there are at least two strategies to apply:

Riffle[{e1,e2,…},{x1,x2,…}] gives {e1,x1,e2,x2,...}

Transpose[{{a, b, c}, {x, y, z}}] gives {{a, x}, {b, y}, {c, z}}

with

x = {0.1, 0.2, 0.3, 0.4, 0.5};
y = {2, 3.5, 6, 7, 8};

you can use:

ListPlot[Partition[Riffle[x, y], 2],
 AxesOrigin -> {0, 0},
 PlotMarkers -> Automatic, Frame -> True, GridLines -> Automatic,
 FrameLabel -> {"Text", "Text"},
 PlotLegends -> Placed[{"Values"}, Bottom], 
 PlotStyle -> Directive[PointSize[Medium], Red]]

enter image description here

ListLinePlot[Transpose@{x, y}, AxesOrigin -> {0, 0}, 
 PlotMarkers -> Automatic, Frame -> True, GridLines -> Automatic,
 FrameLabel -> {"Text", "Text"},
 PlotLegends -> Placed[{"Values"}, Bottom], 
 PlotStyle -> Directive[PointSize[Medium], Blue]]

enter image description here

Nota Bene: [Riffle[y, x] or Transpose@{y, x} works as well, if you find some sense in it.

share|improve this answer
    
Thank you very much for the answer. It is definitely nicer than the first answer. I hope you will appreciate that I accept the first correct answer.(+) –  Seyhmus Güngören May 26 at 20:38
    
Yeah. Way better than my answer. Well done. –  abrentonc May 27 at 2:13
add comment

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