# Do/For loop for plots

I have a lot of points that I would like to get shown on a plot. The problem is that sometimes I only have 2 points while other times i have 10 points. I've tried to make a for loop to create a plot with the points but without any luck. This is my code I have for now:

Point1 = {x -> 2, y -> 4};
point1dot =
ListPlot[{{Point1[[1, 2]], Point1[[2, 2]]}},
PlotStyle -> {AbsolutePointSize[5]}];
Label1 = Graphics[
Text[StyleForm["Point 1", FontSize -> 9], {Point1[[1, 2]] + 0.25,
Point1[[2, 2]] + 0.25}]];
Show[point1dot, Label1]


In this example there is only one point, but sometimes it will look like this:

Point1= {x -> 2, y-> 4};
Point2= {x -> 4, y-> -1};
Point3= {x -> 6, y-> 2};
Point4= {x -> 11, y-> 4};
Point5= {x -> 4, y-> 5};
Point6= {x -> 3, y-> -1};


It will become a great shortcut for my work if it could generate it itself instead of editing it manually all the time. So here is my question:

Is it possible to make some sort of for loop (it doesn't have to be for), that takes value from my points and create a listplot with the label based on the amount of different numbers?

• You don't need your points to have the form {x -> x0, y -> y0}; ListPlot[] only needs a list of points (lists of length two), e.g ListPlot[{{2, 4}, {4, -1}}]. – J. M. is in limbo Apr 15 '13 at 10:51
• Oh yes. I haven't told that I am given the Points, and therefore cannot change them. – Jens Jensen Apr 15 '13 at 10:58
• You can extract the points using points = {x, y} /. {Point1, Point2, Point3, Point4, Point5, Point6} – cormullion Apr 15 '13 at 11:03
• cant change the points huh. oh yea, what say you to this im = WolframAlpha["chuck norris picture", "PodImages"][[2]]; Append[Symbol["Point"<>ToString[#]], im] & /@ Range[6] – amr Apr 15 '13 at 15:54

Not sure what do you plan to do with it. Something doesn't sound right, but anyway:

plot[a : {{x -> _?NumericQ, y -> _?NumericQ} ..}] :=
Show[ListPlot[#, PlotStyle -> AbsolutePointSize[5],
Epilog -> MapIndexed[Inset[StyleForm["Point " ~~ ToString@#2[[1]],
FontSize -> 9], #1 + .1] &, #]] &@({x, y} /. a)]

plot[{{x -> 2, y -> 4}, {x -> 2, y -> 3}, {x -> 2, y -> 2}}]


• This was what I needed. However I wonder why when I want to show it with other plots the labels disappear. – Jens Jensen Apr 15 '13 at 13:12
• @JensJensen Please post an example – Dr. belisarius Apr 15 '13 at 13:14
• With changing the PlotRange i solved the problem. – Jens Jensen Apr 15 '13 at 13:32
(* Create some points in a list *)
points = RandomInteger[10, {10, 2}];

(* Make some labels for each of the points,here they are the Sum of the coordinates *)
labels = Graphics[Text[Plus @@ #, {0.1, 0.1} + #] & /@ points];

(* Display the plot of the points and the associated labels *)
Show[ListPlot[points], labels]