Shading between vertical lines in MATLAB

◇◆丶佛笑我妖孽 提交于 2019-12-04 05:02:59
zellus

Very basic example about shading an area in a plot. Shading an area boundered by a curve might be of interest as well.

figure;
ha = area([4 6], [10 10]);
hold on
plot(1:10, 1:10,'r')
axis([1 10 1 10])
hold off

Instead of area, you can also use fill, which can be a bit more intuitive in terms of usage.

figure;
plot(1:10, 1:10,'r');

% Define the "shading"
% Note how each x_points(i) corresponds to y_points(i)
x_points = [5, 5, 7, 7];  
y_points = [0, 10, 10, 0];
color = [0, 0, 1];

hold on;
a = fill(x_points, y_points, color);
a.FaceAlpha = 0.1;

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!