user877329
user877329

Reputation: 6200

Color datapoints individually

Is it possible to color datapoints individually with a single plot command like

plot(X,'color',colors);

Or do I need a loop for that:

for k=1:length(X)
    plot(k,X,'.','color',colors(k,:));
    hold on
end

Upvotes: 0

Views: 31

Answers (1)

Andy
Andy

Reputation: 8091

Use "scatter". You can specify the color as RGB values or index into a colormap. One example

x = randn (100, 1);
y = randn (100, 1);
c = randi (20, 100, 1);
scatter(x, y, 10, c, ".")

Upvotes: 2

Related Questions