Fill area between plot and the 0-line?

230 ビュー (過去 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 Center および File ExchangeSurface 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