# Scatter chart with colours from dark to light along the x-axis and blue to red along the y-axis

3 visualizaciones (últimos 30 días)
T el 4 de En. de 2023
Comentada: William Rose el 17 de En. de 2023
Hi,
I made a scatter based on interpolation of RGB colours (using only R and B) based on the y-axis data. Now I want the colours to change from dark to light based on the data of x axis. How can I do that? Thanks in advance!
Here is what I have right now and what I get:
b = [0 0 1]; % Blue
r = [1 0 0]; % Red
x =[27.5 26.8 68 70.5 43.5 45.2 72];
y = [7.2 3 7.9 1.7 4.23 1.057 0.89];
y_min_max = [min(y);max(y)];
color = interp1(y_min_max,[b;r],y);
figure()
s = scatter(x,y,80,color,'filled');
grid on; grid minor; box on
xlabel('x')
ylabel('y')
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

William Rose el 5 de En. de 2023
Editada: William Rose el 5 de En. de 2023
b = [0 0 1]; % Blue
r = [1 0 0]; % Red
%x =[27.5 26.8 68 70.5 43.5 45.2 72];
%y = [7.2 3 7.9 1.7 4.23 1.057 0.89];
x = rand(1,1000);
y = rand(1,1000);
y_min_max = [min(y);max(y)];
color = interp1(y_min_max,[b;r],y); %initial color based on y value
lightness=(x-min(x))/(max(x)-min(x)); %lightness of each point, in [0,1]
lightness=repmat(lightness',1,3);
color2=color.*lightness; %adjust lightness of each point
figure()
s = scatter(x,y,80,color2,'filled');
grid on; grid minor; box on
xlabel('x')
ylabel('y')
Good luck.
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
T el 16 de En. de 2023
Thanks William!
William Rose el 17 de En. de 2023
@T, you're welcome. The answer I posted as a comment is better, in my opinion, than my initial answer. Good luck.

Iniciar sesión para comentar.

### Categorías

Más información sobre Scatter Plots en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by