Rescale points plotted using scatter3 based on their distance from the origin
5 views (last 30 days)
Show older comments
James Peach
on 28 Sep 2020
Commented: James Peach
on 28 Sep 2020
I wanted to know if its possible to rescale the markersizes used in scatter3 based on the marker's distance from the origin (0,0,0). I would like to make it so that if a point is closer to center then it is larger than the next point closests to it. Basically, I am hoping to have the largest points closer to the center and the smallest points farther away.
Here is the set of points that I am trying to rescale their markers. the biggest marker should be at (0,0,0) and then the rest should get smaller as they moved away from the center.
A = [0 0 0
0.00977495601952172 0.0129188554738323 0.999868768093125
-0.566794094824837 -0.823750570492204 0.0133959578031223
0.0279587435128966 0.0380588867245362 1.99938731654588
0.830388266617646 0.583999369869120 0.978401571089338
-1.07826433834531 -1.64452537544960 0.267810795303313
0.168715496407312 0.263085998125572 2.96351922435162
-0.791458202545459 0.611268411797120 0.998070417818667
-1.41124221175034 -0.289407593850698 0.0506110237693017
1.69942938355116 1.04462646221878 1.15892918358242
-1.55216375501531 -2.44987966243271 0.623934110066297
0.188310075544404 0.501770043093754 3.93441879647330
-1.44603145623221 1.35107113546187 1.15371676572365
-2.35391403973316 0.0183196401577155 0.179737992978120
2.59879677816763 1.38804628951095 1.42948622326796
-1.92629974765512 -3.28302931738291 1.03122259685150
0.190461468181228 0.731318108759712 4.90771374511875
-2.01837467713375 2.14014570650778 1.37684130228734
-3.30531517848174 0.217844651708771 0.414313445558867
3.50709118523837 1.65551615551852 1.75113998255253
-2.23204460424917 -4.13488361866807 1.45650407075820
0.193343935566412 0.934427321909631 5.88686559182864
-2.51244231909718 2.97180232130260 1.63030617210704
-4.25650570961388 0.357419056329789 0.689550723301627
4.41845060685608 1.87363023778730 2.10021053665969];
0 Comments
Accepted Answer
Turlough Hughes
on 28 Sep 2020
Edited: Turlough Hughes
on 28 Sep 2020
Yes. Firstly get distances from the origin:
d = sqrt(sum(A.^2,2));
If you have the machine learning & statistics toolbox, you might prefer to use the pdist2 function. Next you need to define an equation where size decreases for increasing values of d, obviously you can define that how you like the following is just an example of one way you could do it:
sz = 5*(max(d) - d + 1) % some function do describe size w.r.t distance from O.
Then its just a case of inputting that into scatter3
scatter3(A(:,1),A(:,2),A(:,3),sz,'fill')
5 Comments
Turlough Hughes
on 28 Sep 2020
You could do it as follows
scatter3(x,y,z,sz,d,'filled')
If you specifically want three groups of color based on the distance, d, you can modify the colormap:
colormap([1 0 0; 0 1 0; 0 0 1])
More Answers (0)
See Also
Categories
Find more on Blue in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!