Adding fading Background color (green --> yellow --> red) to plot(x,y)
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Daniel Leibundgut
el 24 de Mzo. de 2022
Comentada: Mathieu NOE
el 24 de Mzo. de 2022
I would like to add a fading colors into the backoground when using plot(x,y).
starting with green at 1.0 and below, fading to yellow (1.2) and yellow fading to red (1.8 and higher). This color schema shall be appllied in both directions x and y.
The following code does only color fading from green to red but noth using yellow:
xdata = [1.378 1.398 1.467 1.558 1.393 1.277 1.775 1.327];
ydata = [1.350 1.660 1.477 1.615 1.471 1.350 1.959 1.400];
figure(11); clf;
plot(xdata,ydata,'o'); grid;
axis square;
axis([1 2 1 2]);
% only two colors green --> red
hold on;
p = patch([1.00 2.00 2.00 1.00],[1.00 1.00 2.00 2.00],...
[1 0.63 0.48],'FaceVertexCData',[0 1 0; 1 0 0; 1 0 0; 1 0 0],...
'FaceColor','interp','EdgeColor','none','FaceAlpha',0.5); % light red
hold off;
Thank you for your help!
0 comentarios
Respuesta aceptada
Mathieu NOE
el 24 de Mzo. de 2022
hello daniel
try this and tune the pos_yellow parameter to get exactly the visual aspect yu want
xdata = [1.378 1.398 1.467 1.558 1.393 1.277 1.775 1.327];
ydata = [1.350 1.660 1.477 1.615 1.471 1.350 1.959 1.400];
figure(11); clf;
plot(xdata,ydata,'o'); grid;
axis square;
axis([1 2 1 2]);
% 3 colors green --> yellow --> red
hold on;
pos_yellow = 1.4; % try between 1.2 and 1.5 to match visually your expectations
p = patch([1 pos_yellow 2 2 1 1],[1 1 1 2 2 pos_yellow],[1 0.63 0.48],...
'FaceVertexCData',[0 1 0; 1 1 0; 1 0 0; 1 0 0; 1 0 0; 1 1 0],...
'FaceColor','interp','EdgeColor','none','FaceAlpha',0.5); % light red
hold off;
4 comentarios
Más respuestas (1)
Chunru
el 24 de Mzo. de 2022
xdata = [1.378 1.398 1.467 1.558 1.393 1.277 1.775 1.327];
ydata = [1.350 1.660 1.477 1.615 1.471 1.350 1.959 1.400];
figure(11); clf;
plot(xdata,ydata,'o'); grid;
axis square;
axis([1 2 1 2]);
% only two colors green --> red
hold on;
% Adjust the vertex color
% [0 1 0; 1 0 0; 1 1 0; 1 0 0] => G R Y R for the 4 corners
p = patch([1.00 2.00 2.00 1.00],[1.00 1.00 2.00 2.00],...
[1 0.63 0.48],'FaceVertexCData',[0 1 0; 1 0 0; 1 1 0; 1 0 0],...
'FaceColor','interp','EdgeColor','none','FaceAlpha',0.5); % light red
hold off;
0 comentarios
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!