Scatter: Vary the color along the axis x
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arseniy Sleptsov
am 17 Apr. 2020
Beantwortet: Star Strider
am 17 Apr. 2020
Hello,
I want to plot using scatter(). I want to color the dots in a way that all the dots with equal x to be the same color.
Here is the code I tried:
clc; clear all;
x = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5];
y = [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4];
sz = 100;
c = linspace(1,6,length(x));
scatter(x,y,sz,c,'filled','o');
xlim([0 6]);
ylim([0 5]);
Here is what it produces instead the example given in https://www.mathworks.com/help/matlab/ref/scatter.html
The colors vertically are not the same (yes, they are almost similar, but, e.g. on the last column you can see that the yellow dot on the top is different from the orange one on the bottom)

0 Kommentare
Akzeptierte Antwort
Star Strider
am 17 Apr. 2020
Use the ‘x’ vector to determine the dot colours:
scatter(x,y,sz,x,'filled','o');
They all appear to be completely uniform.
.
0 Kommentare
Weitere Antworten (0)
Siehe auch
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!