Colored graph (Known function)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I would like to create a graph similar to this one: (I already know the Mathematical function)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/563161/image.jpeg)
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 Kommentare
Akzeptierte Antwort
SSM
am 26 Mär. 2021
Bearbeitet: SSM
am 26 Mär. 2021
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Legend finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!