Fill three areas in a plot with one line

1 回表示 (過去 30 日間)
leonidas86
leonidas86 2018 年 7 月 11 日
回答済み: Star Strider 2018 年 7 月 11 日
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!

回答 (1 件)

Star Strider
Star Strider 2018 年 7 月 11 日
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];

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by