# Fitting to the data points are not proper

I have a data set, I am trying to join all the data by a line. But I am afraid the plot is not doing it properly.

This is the example (or almost) of my problem:

data = {{0, π}, {π/2, π/2}, {π/2,
3 π/2}, {π, 0}, {π,
2 π}, {3 π/2, π/2}, {3 π/2,
3 π/2}, {2 π, π}};


Now, trying to interpolate the data. Result is

instead of

Sorry, I just downloaded and directly uploaded (as I couldn't get this result). $x,y$ are from $[0,2\pi]$.

• Are you just trying to draw a square? Alternatively do you know that your points lie on the boundary of a square and you are trying to find the boundary? More clarification needed please. – Hugh Apr 28 '18 at 17:31
• @Hugh Yes! This is a misleading fig(sorry for that). My points live on the boundary of the square. – Shamina Apr 28 '18 at 17:33

## 2 Answers

ListLinePlot[data[[FindShortestTour[data][[2]]]],
Frame -> True, AspectRatio -> 1, Epilog -> {Red, PointSize[Large], Point[data]}]


• Thanks! Is there a way to get axis label in terms of pi's? I am not able to get that(for aesthetic) – Shamina Apr 28 '18 at 17:53
• See here and here. – corey979 Apr 28 '18 at 18:18

Your data do lie on the boundary of a square. However their order is not going around the square. Here I plot them and number them.

Graphics[{Point[data],
Table[Text[ToString[n], data[[n]], {1, 1}], {n, Length@data}]}]


By inspection I can see a better order and then I reorder your data and plot.

ord = {1, 2, 4, 6, 8, 7, 5, 3, 1};
data2 = data[[ord]];
Graphics[{Line[data2]}]


Is this what you need or are you looking to do this automatically? That would be much more advanced.