5

I have a 3D scatter plot as below. First 3 columns of the points are the location.

BlockRandom[SeedRandom[123];
pts1 = RandomReal[1, {10, 4}];
pts2 = RandomReal[10, {10, 4}];
]

scatterPlot = ListPointPlot3D[{pts1[[1 ;; 3]], pts2[[1 ;; 3]]}, PlotRange -> All]

enter image description here

As you can see, currently the size of all points are just the same. I want to make the 4th column to be the size of the points. How can I do that?

Many thanks!

kglr
  • 394,356
  • 18
  • 477
  • 896
H42
  • 3,469
  • 7
  • 17

2 Answers2

7

The easiest way is to use BubbleChart3D:

BubbleChart3D[{pts1, pts2}]

enter image description here

If you have to use ListPlot3D here is one way:

lpp3d = Show[ListPointPlot3D[List /@ #[[All, ;; 3]], 
    PlotStyle -> Thread[{#2, PointSize /@ 
     Rescale[#[[All, 4]], MinMax @ Join[pts1[[All, 4]], pts2[[All, 4]]], {.1, .9}/10]}], 
    PlotRange -> All] & @@@ 
 Transpose[{{pts1, pts2}, {RGBColor[0.5, 0.5, 1.],  RGBColor[0.5, 1., 0.5]}}], 
 PlotRange -> All, BoxRatios -> 1, PlotRangePadding -> Scaled[.1]] 

enter image description here

You can post-process to turn Points into Spheres

Replace[lpp3d, {d : Directive[_, Directive[c___, PointSize[s_]]], 
    Point[x_]} :> {Directive[c], Sphere[x, 10 s]}, Infinity]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
2
Graphics3D[
 {PointSize[ #[[4]] /20], Point[{#[[1]], #[[2]], #[[3]]}]} & /@ pts1
 ]
David G. Stork
  • 41,180
  • 3
  • 34
  • 96