필터 지우기
필터 지우기

Fill area between plot and the 0-line?

조회 수: 178 (최근 30일)
Julozert
Julozert 2020년 5월 31일
댓글: Harshit 2022년 10월 31일
Hi,
I want to plot some data to show a difference to a reference value and i want that the curve above zero gets filled red and the area of the plot below zero gets filled with blue.
How do i do that?

채택된 답변

Akira Agata
Akira Agata 2020년 6월 1일
How about using area function?
The following is an example:
% Sample data
x = linspace(0,4*pi,1000);
y = sin(x);
% Extract positive and negative part
yp = (y + abs(y))/2;
yn = (y - abs(y))/2;
% Plot the data using area function
figure
area(x,yp,'FaceColor','r')
hold on
area(x,yn,'FaceColor','b')
  댓글 수: 2
Julozert
Julozert 2020년 6월 1일
thank you very much
Harshit
Harshit 2022년 10월 31일
ni chal ra

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

추가 답변 (2개)

the cyclist
the cyclist 2020년 5월 31일
You can use either the fill or patch command. See the examples there for guidance.
  댓글 수: 3
the cyclist
the cyclist 2020년 5월 31일
The way I would do it is to use your data points to define polygons that are above zero, and polygons that are below zero, and then use patch or fill, to fill them in.
Julozert
Julozert 2020년 5월 31일
How can i use my data points to define polygons?

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


Image Analyst
Image Analyst 2020년 6월 1일

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by