Search code examples
octavescatter-plot

How to assign RGB color to a scatterplot in Octave?


According to this, RGB triplet colors with values from 0 to 1 can be specified in Octave.

How to do that for a scatter plot of two vectors of equal length, where all points will have the same RGB color [0.5,0,0.5]?

I tried the following:

a = randn(100,1);
b = randn(100,1);
scatter(a,b,[0.5,0,0.5],'filled')

error: __scatter__: mx_el_or: nonconformant ar
guments (op1 is 100x1, op2 is 3x1)
error: called from
    __scatter__ at line 52 column 7
    scatter at line 86 column 10

Solution

  • The documentation on scatter() tells you that the syntax is scatter(x,y,s,c), i.e. x-coordinate, y-coordinate, size, colour. Size is the 1D radius of a point and thus is either a scalar, setting all points to equal size, or an array as large as x and y to set each point to an individual size. The error you get is that you specified 3 size values to 100 points.

    This also directly points to the solution: you forgot an argument.
    Simply make all points the same size:

    scatter(a,b,3,[0.5,0,0.5], 'filled')
    

    This will give each point the size 3 and colour as specified by your RGB values.