MATLAB Answers

set color for scatter plot

4 views (last 30 days)
MatG
MatG on 23 Sep 2020
Answered: Star Strider on 23 Sep 2020
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);

  0 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 23 Sep 2020
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 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by