Question: How do we label point coordinates in Pathgraph
using VertexLabels
.
Suppose we have a list of points S
and rearrange them as pathway P
.
Clear["Global`*"]
S = {{-1.5, 1}, {0, 1}, {1.5, 1}, {1.5, 0.1}, {0, -0.1}, {-1.5,
0}, {1, -1.4}, {-1, -1.5}}; (* Random list of points *)
X[1] = S[[2]];
Y[1] = DeleteCases[S, X[1]];
X[x_] := Nearest[Y[x - 1], X[x - 1], 1][[
1]]; (* Takes X2=x1, X3=x2, X4=x3,... *)
Y[x_] := DeleteCases[Y[x - 1],
X[x]]; (* Deletes X1=x0 from the sample S *)
P = Table[X[x], {x, 1, Length[S]}] (* Lists all points in pathway *)
r[i_] := Flatten[
Position[Nearest[S, P[[i]], Length[S]],
P[[i + 1]]]];(* Lists value r_i where P[[i+1]] is the r_i th
smallest value from P[[i]] *)
ListofAllr =
Flatten[Table[
r[i]/Length[P], {i, 1,
Length[S] - 1}]](* List of r[i] for all i *)
DeleteAnomalies[ListofAllr]
IndexofNonOutliers =
Flatten[Position[ListofAllr,
Alternatives @@
DeleteAnomalies[
ListofAllr]]](* Index of non-outliers in the list of r *)
D1 = Table[P[[x]],
Evaluate[{x,
IndexofNonOutliers}]](* Excludes integer i where r_i are outliers *)
DistanceD1 =
Table[EuclideanDistance[P[[x]], P[[x + 1]]],
Evaluate[{x,
IndexofNonOutliers}]] ;(* {x,IndexofNon-Outliers} removes the
distance line segments with index i such that r_i is an outlier *)
arrow[coord_, e_] :=
Piecewise[{{Style[Arrow[coord], Red, Thickness[.01],
Arrowheads[0.06]],
Boole[MemberQ[N /@ D1, First@coord]] == 0}, {Style[Arrow[coord],
Blue, Thickness[.01], Arrowheads[0.06]],
Boole[MemberQ[N /@ D1, First@coord]] ==
1}}];(*Labels arrows for "pathway" P*)
Where we attempt to label the point coordinates of the Pathway using:
Edge = PathGraph[Range[Length[P]], VertexCoordinates -> P,
EdgeShapeFunction -> arrow, ImageSize -> 300,
PlotRangePadding -> .2,
VertexLabels -> {Table[{i[[1]], i[[2]]} -> {P[[i]][[1]],
P[[i]][[2]]}, {i, Length[P]}]}]
(* [Above] Illustrates Pathway*)
However, we instead get:
Reformulated Question: How do we fix the code to label the coordinates in the illustration above?