How do I get more colours for scatter plot?
156 views (last 30 days)
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.
delta = SE1Ab(i:i+5,1);
complex = SE1Ab(i:i+5,2);
for n = 1:21:147
delta1 = SE1Ad(n:n+20,1);
complex1 = SE1Ad(n:n+20,2);
Cris LaPierre on 15 Jul 2021
Edited: Cris LaPierre on 15 Jul 2021
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);
Now recreate the same plot using a custom color order (10 unique colors equally spaced from the parula colormap).
clrs = parula(10);
More Answers (2)
Walter Roberson on 15 Jul 2021
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.