Line graph shading?

조회 수: 17 (최근 30일)
Rob Ing
Rob Ing 2011년 11월 9일
Hi,
I have a line graph with quite a few different lines drawn it. I want to shade regions between a couple of the lines to represent/highlight the area. Is there a function or a method i can use to do such a thing?
Cheers for any help given in advance Regards Rob

채택된 답변

Daniel Shub
Daniel Shub 2011년 11월 9일
The fill command can do this. It requires some careful control of the ordering of the points and the ordering of the lines (hence the fliplr in the example below) ...
doc fill
x = 1:10;
y1 = 1:10;
y2 = 2:11;
h = fill([x, fliplr(x)], [y1, fliplr(y2)], 'r')
You can make it transparent with
set(h, 'FaceAlpha', 0.5)
  댓글 수: 1
Rob Ing
Rob Ing 2011년 11월 9일
This does the trick just nicely.
Just to make it slightly clearer to others, as it took me a good 15-20 mins to figure out exactly what was going on. The fill() uses coordinates. So to make a 10x10 box....
Coordinates in terms x,y....(0,0),(10,0),(10,10),(0,10),(0,0)
x = [0,10,10,0,0]
y = [0,0,10,10,0]
h = fill(x,y, 'r')
Cheers for the help!! Much appreciated.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 11월 9일
I am not aware of any function for it. If you can get the intersection points, or just define the points, you can use patch().
  댓글 수: 1
Rob Ing
Rob Ing 2011년 11월 9일
Cheers for attempting to help but i found my answer in Daniel's answer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by