Colour Code Points Based on (x,y) Coordinates

Hello
Below is an example where I have used the (x,y) coordniates to produce a truecolor [R,G,B] values along each axis and then each point is plotted and colour coded.
x = rand(100,1); y = rand(100,1);
xyColour = [x zeros(size(x)) 1-x] + [1-y 1-y y];
figure(1)
scatter(x,y,20,xyColour,'filled');
xlabel('x'); ylabel('y');
grid on
axis square
xlim([-0.1 1.1]);
ylim([-0.1 1.1]);
If you run this code you will get something like this:
You can see that the colours go from blue in one corner through to bright yellow in the other corner and fade to almost white at the bottom.
While this sort of does what I want, I envisaged having stronger variation across the plot (e.g. bright red moving to bright green and then to bright blue) to make interpretation of the points easier. The reason I want to do this is because the points here represent the result of a measurement. In my case x and y are actually principal components of 522 measurements take across a sample and I wanted to colour code an image of the sample to show where the measurement taken at different positions lie in PC space. The variation in colour is too 'weak' and it can make interpretation difficult.
If anyone can think of a better way to do this so that the colour transition gradient is increased across the plot I would be grateful.
Many thanks

 Respuesta aceptada

Adam
Adam el 10 de Feb. de 2017
hsvColour = [x * 0.9, y, ones(100,1)];
xyColour = hsv2rgb( hsvColour );
Or some variation on the theme maybe gives a brighter variation. I multiplied by 0.9 for Hue just as a quick and dirty way to avoid having red appear at both sides of the x axis as it would with the full circular hue range.

2 comentarios

This is great. I also restricted the saturation as well to avoid everything being white at the bottom of the plot.
hsvColour = [x*0.9, y*0.75+0.25, ones(100,1)];
Thanks
Adam
Adam el 10 de Feb. de 2017
Yes, that is certainly an improvement. When I do this kind of colour variation stuff I tend to limit to a min saturation of 25%. I forgot that here

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Feb. de 2017

Comentada:

el 10 de Feb. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by