Drawing a line to divide two parts of a curve
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nour BS
el 15 de Sept. de 2021
Respondida: Nour BS
el 15 de Sept. de 2021
Hello,
How can I draw a vertical line in a curve to divide two parts of the curve and color the first part?
Thanks in advance,
0 comentarios
Respuesta aceptada
Star Strider
el 15 de Sept. de 2021
Try this —
x = linspace(0, 20);
y = (1-exp(-0.1*x));
xq = 10;
yq = interp1(x,y,xq)
figure
plot(x, y)
hold on
plot([1 1]*xq, [0 yq]) % Vertical Line
Lv = x<=xq;
patch([x(Lv) fliplr(x(Lv))], [zeros(1,nnz(Lv)) fliplr(y(Lv))], 'g', 'FaceAlpha',0.5) % Shaded ARea
hold off
Experiment with my code and your data
.
0 comentarios
Más respuestas (2)
Dave B
el 15 de Sept. de 2021
Editada: Dave B
el 15 de Sept. de 2021
You can draw a vertical line very easily with xline
area works well for filling a part of the curve
x=linspace(-3,3,100);
y=exp(-x.^2);
hold on
cutoff=.35;
area(x(x<cutoff),y(x<cutoff),'FaceAlpha',.2,'EdgeColor','none')
plot(x,y,'LineWidth',2)
xline(cutoff,'LineWidth',2,'Label',"The Value is " + cutoff,'LabelOrientation','horizontal')
0 comentarios
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!