how to plot data points with different color in scatter plot?
30 次查看(过去 30 天)
显示 更早的评论
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....
回答(1 个)
Patrick Kalita
2012-5-24
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!