MATLAB Answers

How to do 3d color gradient plot ?

75 views (last 30 days)
I've a set of data (x,y,z,k) which x y z is the coordinate in 3D plane, and k is the value of that position.
I would like to plot 3D with gradient color of that coordinate (x,y,z) have the value of k ,
if k is high value give them red color if k is low give them blue color.
How can I do that ?

Accepted Answer

Anshika Chaurasia
Anshika Chaurasia on 9 Nov 2020
Hi Teerapong,
It is my understanding that you want to plot 3D coordinates (x,y,z) having color as per the value of k.
For this use scatter3 function. (Refer to documentation provided as hyperlink for more information.)
c = k; % color of circles
scatter3(x,y,z,s,c = k) % s is size of circles and x, y, z are the coordinates
Here c can be a vector or three-column matrix of RGB triplets.
If k is a vector of length equal to x, y, z then the values of c (or k) are linearly mapped to the colors in the current colormap.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by