Hello,
I have 3 arrays of the same length X,Y,intensity.
I would like to plot X and Y with 'x' markers, but I also want to change the color of the marker based on the intensity array (0-100).
Is there an easy way to do this in MATLAB?
Many thanks

 採用された回答

Star Strider
Star Strider 2021 年 11 月 17 日

1 投票

Yes.
x = rand(100,1);
y = rand(100,1);
intensity = randi(99,100,1);
figure
scatter(x, y, 50, intensity, '+')
grid
colormap(turbo)
colorbar
.

4 件のコメント

William McNair
William McNair 2021 年 11 月 17 日
編集済み: William McNair 2021 年 11 月 17 日
Thanks so much! Is it possible with same color but transparacy changes? Or color varies from light to dark?
Star Strider
Star Strider 2021 年 11 月 17 日
As always, my pleasure!
The transparency is generally known as the ‘alpha’ property, and scatter allows MarkerEdgeAlpha and MarkerFaceAlpha to be specified.
The colour varying from light to dark is dependent on the colormap being used. See Input Arguments for a list of available colormaps.
It is also possible to create custom colormaps, for example in the second and third scatter calls —
cm = zeros(25,3);
cm(:,1) = linspace(0.5, 0.75, size(cm,1)).';
figure
hs = scatter(rand(100,1), rand(100,1), 150, randi(50, 100, 1), 'filled', 'p');
hs.AlphaData = 3.5*exp(-(hs.XData - 0.5).^2); % Create Gaussian Transparency Vector Based On X-Coordinate
hs.MarkerFaceAlpha = 'flat';
grid
colormap(turbo)
colorbar
title('Transparency Experiment')
figure
scatter(rand(100,1), rand(100,1), 150, randi(50, 100, 1), 'x')
grid
colormap(cm)
colorbar
title('Custom Colour Experiment #1')
figure
scatter(rand(100,1), rand(100,1), 150, randi(50, 100, 1), 'filled', 'p')
grid
colormap(cm)
colorbar
title('Custom Colour Experiment #2')
This creates a gradient red colormap (experiment with the first two arguments in the linspace call to change it) that scatter then uses to colour the markers. This works better with markers that have faces to fill, however it will work with all of them. These are simply two examples.
.
William McNair
William McNair 2021 年 11 月 17 日
This is extactly what I needed. Thanks again. The matlab comunity is great.
Star Strider
Star Strider 2021 年 11 月 17 日
As always, my pleasure!
Thank you for all of us!
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeColor and Styling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by