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

10 Ansichten (letzte 30 Tage)
Sim am 22 Jun. 2024
Kommentiert: Star Strider am 24 Jun. 2024
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?
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Star Strider am 22 Jun. 2024
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 Kommentare4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden
Sim am 24 Jun. 2024
Bearbeitet: Sim am 24 Jun. 2024
That's great, thanks a lot! Problem solved!
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 am 24 Jun. 2024
As always, my pleasure!
No worries! Often, these sorts of mathematical concepts are difficult to describe.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Scatter Plots finden Sie in Help Center und File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by