shadow in mulitple line plot

9 Ansichten (letzte 30 Tage)
Leander Eikås
Leander Eikås am 4 Mär. 2022
Kommentiert: Les Beckham am 4 Mär. 2022
I want my figure in matlab too look more alike the one I have attached as a picture. Therefore I where wondering if some could show me how I get shadow on the three lines plot. Wil also attached my plot in matlab.

Antworten (2)

Les Beckham
Les Beckham am 4 Mär. 2022
I would recommend reading the documentation for the fill command: https://www.mathworks.com/help/matlab/ref/fill.html
I think it will allow you to do what you want.
Here is a simple example:
x = 0:11;
y = [0 2 3 5 6 7 7 6 5 3 2 0];
fill([x x(1)], [y y(1)], 'blue', 'FaceAlpha', 0.4)
hold on
fill([x x(1)], 0.6*[y y(1)], 'green', 'FaceAlpha', 0.4)
  1 Kommentar
Voss
Voss am 4 Mär. 2022
With this method, if the y values don't start and end at 0 (which is the case in the example image), then the fills don't go all the way down to the x-axis:
x = 0:11;
y = [1 2 3 5 6 7 7 6 5 3 2 1];
fill([x x(1)], [y y(1)], 'blue', 'FaceAlpha', 0.4)
hold on
fill([x x(1)], 0.6*[y y(1)], 'green', 'FaceAlpha', 0.4)

Melden Sie sich an, um zu kommentieren.


Voss
Voss am 4 Mär. 2022
Building on @Les Beckham's answer a little bit (introduce zeros in y to make the patches fill all the way down to the x-axis):
x = 0:11;
y = [1 2 3 5 6 7 7 6 5 3 2 1];
patch(x([1 1:end end]),[0 y 0], 'blue', 'FaceAlpha', 0.4)
hold on
patch(x([1 1:end end]),0.6*[0 y 0], 'green', 'FaceAlpha', 0.4)
  1 Kommentar
Les Beckham
Les Beckham am 4 Mär. 2022
@_ Good catch. Thanks.
My example was pretty simplified. Just intended to show what fill can do.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating, Deleting, and Querying Graphics Objects 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!

Translated by