Fill three areas in a plot with one line

1 visualización (últimos 30 días)
leonidas86
leonidas86 el 11 de Jul. de 2018
Respondida: Star Strider el 11 de Jul. de 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!

Respuestas (1)

Star Strider
Star Strider el 11 de Jul. de 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];

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by