Search code examples
matlabplotcolorscustomizationmatlab-figure

Custom colors gplotmatrix MATLAB


I'm trying to use the function gplotmatrix of MATLAB to create a scattered plot. The problem is that I want to set the colors of the groups using the RGB codes instead of the default colors of Matlab.

For example in the line

gplotmatrix(x,y,group,clr,sym,siz,doleg,dispopt,xnam,ynam)

I have to use something like

clr = 'rb'

if I have two sets and I want to change the colors in Red and Blue.

So I'm asking if instead of declaring clr as a string with the default colors letters, is there an alternative like in the classic plot command where I can declare the colors in RGB, for example as [1 0.2 0].


Solution

  • You can do this by declaring RGB colors in two rows like this: [0 1 0.3; 1 0.2 0]

    Example:-

    load discrim;
    
    figure;
    gplotmatrix(ratings(:,1:2),ratings(:,[4 7]),group,...
        [0 1 0.3; 1 0.2 0],'.o',[],'on','',categories(1:2,:),...
        categories([4 7],:))