필터 지우기
필터 지우기

multiple area with different base values

조회 수: 15 (최근 30일)
Lionel
Lionel 2017년 5월 17일
답변: Ullekh Gambhira 2018년 6월 16일
Is it possible to show multiple area in a graph with different base values ? In the following example, the base value of the first area is changing when the second one is displayed.
figure
x = linspace(0,2*pi);
y = sin(x);
plot(x,y,'linewidth',2);
hold on;
f = y>=0.9;
h(1) = area(x(f),y(f),...
'BaseValue',0.9,...
'ShowBaseLine','off',...
'FaceColor','red',...
'FaceAlpha',0.2,...
'LineStyle','none');
fprintf('basevalue: %.2f\n',h(1).BaseValue);
f = y<=-0.3;
h(2) = area(x(f),y(f),...
'BaseValue',-0.3,...
'ShowBaseLine','off',...
'FaceColor','green',...
'FaceAlpha',0.2,...
'LineStyle','none');
fprintf('basevalue: %.2f\n',h(1).BaseValue);
Thanks for the help ! (Matlab R2016b)
  댓글 수: 1
Lionel
Lionel 2017년 5월 17일
One way to bypass this issue :
figure
x = linspace(0,2*pi);
y = sin(x);
plot(x,y,'linewidth',2);
hold on;
bv = 0.9;
f = y>=bv;
ybv = repmat(bv,1,sum(f));
h = area([x(f);x(f)]',[ybv;y(f)-ybv]',...
'ShowBaseLine','off',...
'FaceColor','red',...
'FaceAlpha',0.2,...
'LineStyle','none');
delete(h(1));
f = y<=-0.3;
h2 = area(x(f),y(f),...
'BaseValue',-0.3,...
'ShowBaseLine','off',...
'FaceColor','green',...
'FaceAlpha',0.2,...
'LineStyle','none');
but...

댓글을 달려면 로그인하십시오.

답변 (2개)

Manish Annappa
Manish Annappa 2017년 5월 19일
I compared the graphs generated from the above code snippets posted by you. The second code snippet seems to give the expected results. Any reason why this solution is not acceptable to you?
  댓글 수: 1
Lionel
Lionel 2017년 5월 19일
Indeed the second code snipped gives the expected results but is much less intuitive. Is is a bug or a feature to have only one BaseValue per axis ?

댓글을 달려면 로그인하십시오.


Ullekh Gambhira
Ullekh Gambhira 2018년 6월 16일
I was facing a similar issue, solved it by using "Shade area between two curves" function by John Bockstege. The file exchange link for this function is below:
https://www.mathworks.com/matlabcentral/fileexchange/13188-shade-area-between-two-curves
It does not consider base value, but basically shades the area between two lines. So one line can be your vector and the other can be a baseline*ones(size(x)).
Hope this helps.
Regards, Ullekh

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by