Adding fading Background color (green --> yellow --> red) to plot(x,y)
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Daniel Leibundgut
il 24 Mar 2022
Commentato: Mathieu NOE
il 24 Mar 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 Commenti
Risposta accettata
Mathieu NOE
il 24 Mar 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 Commenti
Più risposte (1)
Chunru
il 24 Mar 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 Commenti
Vedere anche
Categorie
Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!