Fill three areas in a plot with one line

2 Ansichten (letzte 30 Tage)
leonidas86
leonidas86 am 11 Jul. 2018
Beantwortet: Star Strider am 11 Jul. 2018
Hello, I have one vector with my x axis values, one vector with the y axis values for my line and a min and max value for the y limits of my figure. Now I want to fill the area under the x-axis with one color, the area between the x axis and the line with one color and the area between the line until to my max value with another color. How can I do this?
Thanks for your help!

Antworten (1)

Star Strider
Star Strider am 11 Jul. 2018
I am not certain what you want.
Try this:
x = sort(rand(1, 20));
y = rand(1, 20) + 0.5;
ylow = 0.3; % Low Y-Limit
yhigh = 1.8; % High Y-Limit
x1 = ones(size(x));
figure(1)
patch([x fliplr(x)], [x1*ylow fliplr(y)], 'g')
hold on
patch([x fliplr(x)], [x1*yhigh fliplr(y)], 'r')
patch([x fliplr(x)], [x1*min(ylim) x1*ylow], 'b')
hold off
ylim = [ylow yhigh];

Kategorien

Mehr zu Graphics Object Programming 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