How can I fill a plot section from a single x,y coordinates?
Mostrar comentarios más antiguos
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 comentario
Azzi Abdelmalek
el 21 de Ag. de 2012
can we know if a delimùiter is horizontal or vertical?
Respuesta aceptada
Más respuestas (1)
Azzi Abdelmalek
el 21 de Ag. de 2012
Editada: Azzi Abdelmalek
el 21 de Ag. de 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 comentarios
Azzi Abdelmalek
el 21 de Ag. de 2012
if there is a curve the program must change
Azzi Abdelmalek
el 21 de Ag. de 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
el 21 de Ag. de 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
el 21 de Ag. de 2012
you are right, it's better to use fill,
Categorías
Más información sobre Line Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!