set color for scatter plot

1 次查看(过去 30 天)
How can I set the colors according to the Z value a scatter plot?
Here p2dZ is either 0, 1 or 2. I want an scatter plot where horizontal and vertical coordinate values are as given in pdX and pdY vectors, translated into p2dX and p2dY via meshgrid. But the value at each point comes from the vector p2dZ which is either 0, 1, or 2. However, I want the colors of the points to be set according to the value p2dZ.
how can I set the color in "scatter3(x,y,z,sz,c,'filled')" so the values match the pdZZ which is the 1 dimentional version of p2dZZ?
I don't want to use "imagesc(p2dZZ);colorbar;" as I want to see individual points.
pdX = 1:12;
pdY = 20:-1:1;
[p2dX,p2dY] = meshgrid(pdX, pdY);
p2dZ = round(2*rand(size(p2dX)));
pdXX = p2dX(:)';
pdYY = p2dY(:)';
pdZZ = p2dZ(:)';
scatter3(pdXX, pdYY, pdZZ, 5,'filled');
view(0,90);

采纳的回答

Star Strider
Star Strider 2020-9-23
The colour of the markers is the fifth argument, so:
scatter3(pdXX, pdYY, pdZZ, 5, pdZZ,'filled')
This is a bit more obvious with larger markers (at least temporarily).

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Scatter Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by