简体   繁体   中英

pcolor in scatter plot matlab

I have a large matrix DAT(50000+,42) . I am plotting 2 rows of this matrix on the x and y axes, and want the plot points to vary in color due to the value of a separate row. Can anybody advise? pcolor will not work for me due to "color data input must be a matrix" error. TIA

X = DAT(:,21);

Y = DAT(:,22);

Z = DAT(:,28);

plot(X,Y,'*');

hold on

pcolor(X,Y,Z);

hold off

You could consider using scatter()

% random sample data
DAT = randn(30,42);
X = DAT(:,21);
Y = DAT(:,22);
Z = DAT(:,28);

scatter(X,Y,50,Z); % x,y,size,color -> size can also be a vector
% scatter(X,Y,50,Z,'*'); % to also change the marker type

在此输入图像描述

You can select the colors from an array generated with colormap like this:

DAT = randn(30,42);
X = DAT(:,21);
Y = DAT(:,22);
Z = DAT(:,28);

[dummy ID]=sort(Z);
colors=colormap(jet(length(Z)));

figure
for i=1:length(Z)
plot(X(i),Y(i),'*','Color',colors(ID(i),:));
hold on
end

The only issue with this technique is that you cannot do plots with millions of points because of the looped plotting, but otherwise it works like a charm:

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM