フィルターのクリア

Adding fading Background color (green --> yellow --> red) to plot(x,y)

4 ビュー (過去 30 日間)
Daniel Leibundgut
Daniel Leibundgut 2022 年 3 月 24 日
コメント済み: Mathieu NOE 2022 年 3 月 24 日
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!

採用された回答

Mathieu NOE
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 件のコメント
Daniel Leibundgut
Daniel Leibundgut 2022 年 3 月 24 日
great, thank you!
Mathieu NOE
Mathieu NOE 2022 年 3 月 24 日
My pleasure !

サインインしてコメントする。

その他の回答 (1 件)

Chunru
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;

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by