Create colormap and set it for a plot3(x,y,​z,colormap​_value)

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 comentario

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.

Iniciar sesión para comentar.

Respuestas (1)

DGM
DGM el 22 de Dic. de 2021
Editada: DGM el 22 de Dic. de 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
ans = 1×2
10 100

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Productos

Versión

R2019a

Etiquetas

Preguntada:

el 21 de Dic. de 2021

Editada:

DGM
el 22 de Dic. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by