Adding fading Background color (green --> yellow --> red) to plot(x,y)
조회 수: 4 (최근 30일)
이전 댓글 표시
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
채택된 답변
Mathieu NOE
2022년 3월 24일
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
추가 답변 (1개)
Chunru
2022년 3월 24일
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
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!