Colored graph (Known function)

3 次查看(过去 30 天)
Hidd_1
Hidd_1 2021-3-26
编辑: SSM 2021-3-26
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?!

采纳的回答

SSM
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 个)

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by