How do I get more colours for scatter plot?

조회 수: 21 (최근 30일)
Herline van der Spuy
Herline van der Spuy 2021년 7월 15일
편집: Stephen23 2021년 7월 16일
Hi, I've got ten sets of data (total of 165 points), where 3 sets only have 6 points each, and the other 7 have 21 points each. I want to plot all 10 sets, each with different colours.
So SE1Ab is an 18x2 matrix, where there is 3 sets of data, aka every 6 points. SE1Ad is 147x2 matric, where there are 7 sets, each containing 21 points. The code works, it's just that the first 3 sets of each matrix has the same colour. (I changed the 2nd matrix' set to triangles, just to show where it is.) But I need it all to be the same marker, but each different colours. This is the code I've got, which works, except for the colour thing.
for i=1:6:18
delta = SE1Ab(i:i+5,1);
complex = SE1Ab(i:i+5,2);
scatter(delta,complex)
set(gca,'yscale','log')
hold on
for n = 1:21:147
delta1 = SE1Ad(n:n+20,1);
complex1 = SE1Ad(n:n+20,2);
scatter(delta1,complex1,'^')
end
end

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 7월 15일
편집: Cris LaPierre 2021년 7월 15일
Modify the colororder of your plot. MATLAB uses 7 colors by default, meaning your 8th series reuses the first color, and so on. You can see the values used for the default colororder here.
% using default color order
data = rand(10,10);
scatter(1:10,data,'filled')
legend('Location','eastoutside')
Now recreate the same plot using a custom color order (10 unique colors equally spaced from the parula colormap).
figure
clrs = parula(10);
colororder(clrs)
scatter(1:10,data,'filled')
legend('Location','eastoutside')
  댓글 수: 1
Stephen23
Stephen23 2021년 7월 16일
편집: Stephen23 2021년 7월 16일
Parula, like most of the other inbuilt colormaps, is intended for sequential data and not for qualitative plots (like distinguishing between lines, or between the points of a scatter plot, by using maximally-distinct colors).
You could generate the maximally-distinct colors by downloading my FEX submission:

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Steven Lord
Steven Lord 2021년 7월 15일
See the description of the c input argument on the documentation page for the scatter function. You want the "Assign different colors to each point using a colormap" or "Create a customer color for each point" color schemes.
  댓글 수: 2
Cris LaPierre
Cris LaPierre 2021년 7월 15일
This is probably a cleaner and easier solution to implement than what I shared.
Herline van der Spuy
Herline van der Spuy 2021년 7월 16일
I got it, thank you!! *insert really big smiley face*

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2021년 7월 15일
First parameter to scatter is x, second is y, third is point size, fourth is color information. The color information can be a single color name or a 1 x 3 vector of rgb, or an N x 3 array of rgb, one row per point.
You do not need your loop, by the way. Just submit all your points at the same time, passing in color information of corresponding size.
Exception: if you need to generate a legend entry for each group.
... if you do need a legend entry for each group then sometimes gscatter() is a better choice.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by