How can I fill a plot section from a single x,y coordinates?
이전 댓글 표시
Hello,
I simply want to fill an unbounded section of a plot from an x,y coordinate. For example, the code below creates a vertical line that divides a plot area into two unbounded regions. I would like to fill in the plot area to the left (indicated by the red circle). Is there a simple way to achieve this? Polygons could be a possible solution, but it may get complicated since the line is not always vertical and the data point could be anywhere.
y=0:100;
x=ones(size(y));
plot(x,y)
hold all
scatter(0.5,50,'r')
axis([0 2 0 100])
Thanks
댓글 수: 1
Azzi Abdelmalek
2012년 8월 21일
can we know if a delimùiter is horizontal or vertical?
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2012년 8월 21일
편집: Azzi Abdelmalek
2012년 8월 21일
close;
xmin=0;xmax=2;ymin=0;ymax=100
choice=2
y=0:100;
x=ones(size(y));
plot(x,y)
hold all
axis([xmin xmax ymin ymax]);
n=length(y);
if choice==1
x1=[x xmin xmin x(1)];y1=[y ymax ymin y(1)];
fill(x1,y1,'r')
elseif choice==2
x1=[x xmax xmax x(1)] ;y1=[y ymax ymin y(1)];
fill(x1,y1,'r')
end
댓글 수: 7
Azzi Abdelmalek
2012년 8월 21일
if there is a curve the program must change
Azzi Abdelmalek
2012년 8월 21일
if choice==1, it fills on the left, if choice==2 it fills on the right. and it may work even it's a curved
Matt Fig
2012년 8월 21일
Is this what you mean by 'fill' in your question? I was picturing more like to make the region all one color.
Azzi Abdelmalek
2012년 8월 21일
you are right, it's better to use fill,
카테고리
도움말 센터 및 File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!