3
$\begingroup$

I'm trying to connect pairs of corresponding points from two lists in a ListPointPlot3D (similar to what was done here but in 3D). Filling-> {1->{2}} isn't working for me, so I presume the problem must lie in how I'm passing the two lists.

SeedRandom[11];
sigma = DiagonalMatrix[{0.001, 0.001, 0.000001}];
sp = 5;
means1 = Flatten /@ 
   Transpose[{Table[RandomReal[{0, 1}, 2], {sp}], Table[0.8, {sp}]}];
dist1 = MixtureDistribution[Table[1, {sp}],
   Table[MultinormalDistribution[means1[[i]], sigma], {i, 
     Table[j, {j, sp}]}]
   ];
means2 = Flatten /@ 
   Transpose[{Table[RandomReal[{0, 1}, 2], {sp}], Table[0.2, {sp}]}];
dist2 = MixtureDistribution[Table[1, {sp}],
   Table[MultinormalDistribution[means2[[i]], sigma], {i, 
     Table[j, {j, sp}]}]
   ];
n = 50;
data1 = RandomVariate[dist1, n];
data2 = RandomVariate[dist2, n];
ListPointPlot3D[{data1, data2}, PlotRange -> {{0, 1}, {0, 1}, {0, 1}},
  Filling -> {1 -> {2}}]
$\endgroup$
  • 1
    $\begingroup$ It seems that for ListPointPlot3D the Filling limits can only be Top, Bottom, Axis or None. Does Graphics3D[{PointSize[Medium], Red, Point[data1], Blue, Point[data2], Gray, Line /@ Transpose[{data1, data2}]}, Boxed -> True] give what you need. $\endgroup$ – kglr May 3 at 20:26
  • $\begingroup$ Almost! What I'd like to for each point in the top layer to be connected to only one point in the bottom layer. Which point is connected to which is determined by their position (order) in the data (i.e. first point in data1 connects to first point in data2). thanks $\endgroup$ – user12734 May 3 at 22:06
  • $\begingroup$ user12734, Transpose[{data1, data2}] pairs points from data1 and data2 based on position. $\endgroup$ – kglr May 3 at 22:41
2
$\begingroup$
Show[ListPointPlot3D[{data1, data2}, PlotStyle -> {Red, Blue}, 
    PlotLegends -> {"data1", "data2"}], 
  Graphics3D[{Gray, Line @ Transpose[{data1, data2}]}]]

enter image description here

Alternatively, you can use Graphics3D to plot both points and connecting lines:

Legended[Graphics3D[{PointSize[Medium], Red, Point[data1], Blue, 
      Point[data2], Gray, Line /@ Transpose[{data1, data2}]}, BoxRatios -> {1, 1, 0.4}], 
  PointLegend[{Red, Blue}, {"data1", "data2"}]]

enter image description here

$\endgroup$
  • $\begingroup$ You're exactly right! I was thinking about my data incorrectly. thanks! $\endgroup$ – user12734 May 3 at 23:16
0
$\begingroup$

The following might be useful for others to see my mistake:

SeedRandom[11];
sp = 4;
maxVar = 0.02;
means = Table[RandomReal[{0, 1}, 2], {sp}];
dist = MixtureDistribution[Table[1, {sp}],
   Table[BinormalDistribution[means[[i]], 
     RandomReal[{0.01, maxVar}, 2], 0.5], {i, Table[j, {j, sp}]}]
   ];
n = 50;
pos = RandomVariate[dist, n];
data1 = Flatten /@ Transpose[{pos, Table[0.8, {n}]}];
data2 = Flatten /@ Transpose[{pos, Table[0.2, {n}]}];

Show[ListPointPlot3D[{data1, data2}, PlotStyle -> {Red, Blue}, 
  PlotLegends -> {"data1", "data2"}], 
 Graphics3D[{Gray, Line@Transpose[{data1, data2}]}]]
$\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.