6
$\begingroup$

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

enter image description here

instead of

enter image description here

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

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Hugh Apr 28 '18 at 17:31
  • $\begingroup$ @Hugh Yes! This is a misleading fig(sorry for that). My points live on the boundary of the square. $\endgroup$ – Shamina Apr 28 '18 at 17:33
11
$\begingroup$
ListLinePlot[data[[FindShortestTour[data][[2]]]],
 Frame -> True, AspectRatio -> 1, Epilog -> {Red, PointSize[Large], Point[data]}]

enter image description here

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

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}]}]

Mathematica graphics

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]}]

Mathematica graphics

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

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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