How can I "connect" the colorbar to my values of a scatter plot?

7 ビュー (過去 30 日間)
Sim
Sim 2024 年 6 月 22 日
コメント済み: Star Strider 2024 年 6 月 24 日
How can I "connect" the colorbar to my values (between 0 and 1) of a scatter plot?
a = rand(1000,1);
C = 1-[a a a];
scatter(1:length(a),a,60,C,'fill')
colormap(C);
colorbar;
Here you can see that the colorbar is not gradually changing from 0 to 1.. How to fix it?

採用された回答

Star Strider
Star Strider 2024 年 6 月 22 日
I am not certain what you want to do, or what you intend by ‘connect’.
One option —
a = rand(1000,1);
% C = 1-[a a a];
C = ([1;1;1]*linspace(1, 0, 1000)).';
scatter(1:length(a),a,60,C,'fill')
colormap(C);
colorbar;
.
  6 件のコメント
Sim
Sim 2024 年 6 月 24 日
編集済み: Sim 2024 年 6 月 24 日
That's great, thanks a lot! Problem solved!
I was not sure about this code:
a = rand(1000,1);
C = 1-[a a a];
scatter(1:length(a),a,60,C,'fill')
l = linspace(1,0,1000)';
colormap([l l l])
colorbar
but your further check - with the two red and green points -, confirmed what I was thinking/expecting :-)
Thanks a lot for your great support!
And, I am really sorry for my confusion... My fault :-)
Star Strider
Star Strider 2024 年 6 月 24 日
As always, my pleasure!
No worries! Often, these sorts of mathematical concepts are difficult to describe.

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

その他の回答 (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