set color for scatter plot

조회 수: 1 (최근 30일)
MatG
MatG 2020년 9월 23일
답변: Star Strider 2020년 9월 23일
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