How can I fill a plot section from a single x,y coordinates?
Show older comments
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 Comment
Azzi Abdelmalek
on 21 Aug 2012
can we know if a delimùiter is horizontal or vertical?
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 21 Aug 2012
Edited: Azzi Abdelmalek
on 21 Aug 2012
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 Comments
Azzi Abdelmalek
on 21 Aug 2012
if there is a curve the program must change
Azzi Abdelmalek
on 21 Aug 2012
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
on 21 Aug 2012
Is this what you mean by 'fill' in your question? I was picturing more like to make the region all one color.
Azzi Abdelmalek
on 21 Aug 2012
you are right, it's better to use fill,
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!