how to plot data points with different color in scatter plot?

42 Ansichten (letzte 30 Tage)
Lei
Lei am 24 Mai 2012
hello,everyone. I have a very large matrix, thousands of rows and 15 columns. Now i wanna analyze four variables(columns). I used the scatter plot for plotting each of the two variables. My question is how can I plot different colors for different groups of data in scatter plot. I wrote a if statement but its very slow, so I am wondering anyone have any better ways to do it.
for i=1: length(PaskapooFm4(:,14));
if PaskapooFm4(i,14)==1
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'.b');hold on;
elseif PaskapooFm4(i,14)==2
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'.g');hold on;
elseif PaskapooFm4(i,14)==3
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'.r');hold on;
elseif PaskapooFm4(i,14)==4
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'.c');hold on;
elseif PaskapooFm4(i,14)==5
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'.m');hold on;
elseif PaskapooFm4(i,14)==6
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'.y');hold on;
elseif PaskapooFm4(i,14)==7
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'.b');hold on;
elseif PaskapooFm4(i,14)==8
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'h');hold on;
elseif PaskapooFm4(i,14)==9
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'>');hold on;
elseif PaskapooFm4(i,14)==10
scatter(PaskapooFm4(i,3),PaskapooFm4(i,12),'<');hold on;
end
xlabel('GAMMA(API)');ylabel('RES(DG)(OHM-M)');
title('Crossplot of Gamma and RESD')
end
the above code used to plot two variables (column 3 and column 12), and each row is in 10 categories as indicated by column 14. Column 14 are just numbers: 1 to 10. So what i did here is using scatter plot for plotting the two varibales and assign different color for each number( 1 to 10). However, this is very slow and the code is long. Anybody could think of a better way? Many thanks! BTW, I also need to figure out those 4 variables' relationship. How can I fit a best line to the scatter plot? because there are so man different ones(liner,quadratic,third order...). I mean how can I decide which one is the best fit. Or any other better ways to visualize multidimensional data? I tried to use plotmatrix,pca. etc....
  2 Kommentare
Oleg Komarov
Oleg Komarov am 24 Mai 2012
Have you checked gscatter?
Lei
Lei am 24 Mai 2012
Hi oleg,I did!
But i am not sure about the meaning of group in gscatter cauz I have created my own group,which is column 14 (number 1 to number 10),i.e., 10 different groups. I thought my group is different from the group in gscatter, am I right? I am not sure about this

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Patrick Kalita
Patrick Kalita am 24 Mai 2012
You can use the fourth input argument to scatter to control the color of each marker in the scatter plot. For example:
scatter(PaskapooFm4(:,3), PaskapooFm4(:,12), [], PaskapooFm4(:,14));
Note that it will only change the color of the marker, not the shape of the marker.

Community Treasure Hunt

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

Start Hunting!

Translated by