Colored graph (Known function)
1 回表示 (過去 30 日間)
古いコメントを表示
I would like to create a graph similar to this one: (I already know the Mathematical function)

I can draw the function, but to color the right side and left side was for me hard to achieve.
Anybody has an Idea how can I do that?!
0 件のコメント
採用された回答
SSM
2021 年 3 月 26 日
編集済み: SSM
2021 年 3 月 26 日
Use the patch() function.
Example:
%%% Create sample data
x = 0:1:100;
y = sin(x);
plot(x,y)
patch([x fliplr(x)], [y max(ylim)*ones(size(y))], 'r') %%% Patch the area above the sine curve red
patch([x fliplr(x)], [y min(ylim)*ones(size(y))], 'r') %%% Patch the area below the sine cutve blue
legend() %%% Add the legend here
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Legend についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!