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 Center および File ExchangeScatter Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by