5
$\begingroup$

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!

$\endgroup$
1
7
$\begingroup$

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

$\endgroup$
2
$\begingroup$
Graphics3D[
 {PointSize[ #[[4]] /20], Point[{#[[1]], #[[2]], #[[3]]}]} & /@ pts1
 ]
$\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.