How is it possible to show "links/alingments" between 2 sets of points using PGFPlotsX.jl?

I am working on point cloud alignment model and want to show the initial alignment vs the final alignment on a 2d dataset. I also want to show the alignment between point pairs just for curiosity.

For demonstration purposes (which I “inspired” by the PGFPlotsX examples) :


using PGFPlotsX
using SyntheticDatasets:make_moon

MoonData = make_moons(n_samples=200, shuffle=true, noise=0.02);
X, Y = Matrix(MoonData[:, 1:2]), MoonData[:, 3];

# plotting 
 @pgf Axis(
           {
               "scatter/classes" = {
                   0 = {mark = "square*", "blue"},
                   1 = {mark = "triangle*", "red"},
               }
           },
            Plot(
               {
                   scatter,
                   "only marks",
                   "scatter src" = "explicit symbolic",
               },
            Table(
                   {
                       meta = "label"
                   },
                   x = X[:, 1],
                   y = X[:, 2],
                   label = Y,)),)

This plots the initial state of 2 point clouds. In addition to this, I also want to plot the initial unrelated alignments which I tried with the following:


blues = X[1:100, :];
reds  =  X[101:end, :];  
F = reshape(hcat(blues, reds)', 2, 200) |> permutedims

@pgf Axis(
           {
               "scatter/classes" = {
                   0 = {mark = "square*", "blue"},
                   1 = {mark = "triangle*", "red"},
               }
           },
            Plot(
               {
                   scatter,
                   "only marks",
                   "scatter src" = "explicit symbolic",
               },
            Table(
                   {
                       meta = "label"
                   },
                   x = X[:, 1],
                   y = X[:, 2],
                   label = Y,)),
          for i in 1:2:size(F, 1) - 1
               Plot(Table(F[i:i+1, :]))
               end )

The variable F represents the data points which “should” be related. So F[1, :] and F[2, :] are related.
F[3, :] and F[4, :] are related and so on (F[i, :] ,F[i+1, :] )

When I try the above code, unfortunately it gives the following error :

ERROR: `Nothing` does not support the Table interface

How is it possible to show a “link” between 2 sets of points ?

B.R.

Ok, here is the solution I came with:


 @pgf gp = Axis(
                  {
                      "scatter/classes" = {
                          0 = {mark = "square*", "blue"},
                          1 = {mark = "triangle*", "red"},
                      }
                  },
                   Plot(
                      {
                          scatter,
                          "only marks",
                          "scatter src" = "explicit symbolic",
                      },
                   Table(
                          {
                              meta = "label"
                          },
                          x = X[:, 1],
                          y = X[:, 2],
                          label = Y,)),)

c = hcat(blues, reds)
P = [c[i, :] for i in 1:size(c, 1)];

 @pgf for (i, ps) in enumerate(P)
           push!(gp, PlotInc(Coordinates(ps)))
 end

I did not imagine that PGFPlotsX has such easiness.

Edit: Adding some more colors :

using Colors
colors = [LCHuv(65, 100, h) for h in range(15; stop = 360+15, length = n+1)][1:size(P, 1)]

@pgf for (i, ps) in enumerate(P)
           push!(gp, PlotInc({color=colors[i]}, Coordinates(ps)))
  end

1 Like