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

조회 수: 25 (최근 30일)
Patrick
Patrick 2013년 5월 4일
댓글: Mohammad 2020년 9월 25일
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
Mehmet Ozturk
Mehmet Ozturk 2018년 1월 29일
Works Great! Thanks.
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