# Making a scatter plot from the elements of two arrays [closed]

So, I want to create two vectors using a For.

Example:

Array[a, 5];
For[i = 1, i <= 5, i++, a[5] = i/5]
Array[b, 5];
For[i = 1, i <= 5, i++, b[5] = i/6]


And after that, I would like to plot the points {a[i], b[i]} and draw lines between them. I searched on the internet, but I couldn't find anything.

## closed as off-topic by Michael E2, m_goldberg, Coolwater, Henrik Schumacher, LCarvalhoDec 23 '17 at 11:35

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." – Michael E2, m_goldberg, Coolwater, Henrik Schumacher, LCarvalho
If this question can be reworded to fit the rules in the help center, please edit the question.

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Dec 23 '17 at 1:25
• ListLinePlot[Table[{a[i], b[i]}, {i, 5}]]? – Michael E2 Dec 23 '17 at 1:25

You shouldn't need a For statement, while Table is far superior:

ListPlot[Table[{i/5, i/6}, {i, 5}],
Joined -> True,
PlotMarkers -> Green,
PlotStyle -> Red]

• If you want to be able to retrieve the a and b arrays later, you can set {a, b} = Transpose@Table[{i/5, i/6}, {i, 5}], so that, for example, b[[3]] == 1/2. For plotting the {a[i], b[i]} points from there, use ListPlot[Transpose@{a, b}, **options**]. – aardvark2012 Dec 22 '17 at 23:55

want to create two vectors using a For

(1) Assign values to a and b inside For:

For[i = 1, i <= 5, i++, a[i] = i/5]
For[i = 1, i <= 5, i++, b[i] = i/6]


(2a) Create data pairs directly using Array:

data = Array[{a @ #, b @ #}&, 5]


(2b) Alternatively, name two arrays, say aa and bb, then create pairs using Transpose:

{aa, bb} = Array[#, 5] & /@ {a, b};
data = Transpose[{aa, bb}];


(3) ListPlot data:

ListPlot[data, PlotStyle -> PointSize[Large],
Frame -> True, AspectRatio -> 1, PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> False, PlotRangePadding -> .1]


Note: You can also reverse the order of steps (1) and (2) to get the same result.

Update: For the case in comments:

But if I have a vector like this: For[ i=1, i<=n, i++, v[i] = Point[{i/2, i/3}]], how can I plot it?

n = 10;
For[i = 1, i <= n, i++, v[i] = Point[{i/2, i/3}]]
Graphics[{Red, PointSize@Large, Array[v, 10]}, Frame -> True, AspectRatio -> 1]


Alternatively, use v / @ Range[10] in place of Array[v, 10] to get the same result.

• But if I have a vector like this: For[ i=1, i<=n, i++, v[i] = Point[{i/2, i/3}]], how can I plot it? – Princeton Dec 24 '17 at 20:44
• @Princeton, please see the update. – kglr Dec 24 '17 at 20:58
• And having the same type of vector, how can I draw lines between the points? I can't figure out a syntax for ListLinePlot if this is what is needed. – Princeton Dec 24 '17 at 21:16
• Add Line[Join @@ List @@@ Array[v, 10]] after Array[v, 10] in Graphics. If you have to use ListLinePlot you can do ListLinePlot[Join @@ List @@@ Array[v, 10], Epilog -> Array[v, 10]]. – kglr Dec 24 '17 at 21:24