How to add two vertical lines to plot and color between them?

29 次查看(过去 30 天)
Hi,
I want to highlight a period in my plot by adding two vertical lines and coloring between them. Any ideas on how to do that?

采纳的回答

the cyclist
the cyclist 2013-5-4
Here's one way:
figure
%Plot something
plot(1:10)
% Add lines
h1 = line([2 2],[1 10]);
h2 = line([5 5],[1 10]);
% Set properties of lines
set([h1 h2],'Color','k','LineWidth',2)
% Add a patch
patch([2 5 5 2],[1 1 10 10],'r')
% The order of the "children" of the plot determines which one appears on top.
% I need to flip it here.
set(gca,'children',flipud(get(gca,'children')))
  5 个评论
Mohammad
Mohammad 2020-9-25
How can I add grid to the figure which is not covered by the patch color?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by