Create colormap and set it for a plot3(x,y,z,colormap_value)
72 views (last 30 days)
Show older comments
I have a set of (x,y,z,power) data. I would like to plot3(x,y,z,'*') with each data point * shown with the corresponding colormap value of power.
I know how to generate a colormap that matches the span of 10 to 100 that power is limited to but I do not know how to plot3(x,y,z,'*') with the specific color.
1 Comment
Voss
on 21 Dec 2021
I don't think there is a way to create a line (e.g., from plot or plot3) where the color varies within the line. Any line is one and only one color (same for MarkerEdgeColor, MarkerFaceColor, etc.).
But you can make several lines - one per color from the set of colors you want. Split your x,y,z data according to power ranges and plot3 one line for each subset of x,y,z, data with the corresponding color.
Or you may consider using graphics object(s) other than lines. A surface may be appropriate, for instance.
Answers (1)
DGM
on 22 Dec 2021
Edited: DGM
on 22 Dec 2021
That should be simple enough. Since you're plotting markers only, just use scatter3().
n = 50;
t = linspace(0,pi,n);
x = cos(t);
y = sin(t/2);
z = linspace(1,10,n);
power = z*10;
% first three arguments are position data
% fourth argument is marker size
% fifth argument is color data
h = scatter3(x,y,z,20,power);
h.MarkerFaceColor = 'flat';
grid on
colormap(jet)
colorbar
caxis % show that the colorbar/colormapping corresponds to power extents
0 Comments
See Also
Categories
Find more on Colormaps 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!