Borrar filtros
Borrar filtros

Plot a shadow between to lines for a current figure without legend

8 visualizaciones (últimos 30 días)
Hi, I want to fill with light gray shadow (how to control the color?) between my two vertical line, xline(1), xline(10), the height is just consisent with the figure. and I don't want legend for xline(1) and xline(10) Thank you
figure
le=[1,2,3];
x=[0 5 15];
y=2*x;
for i =1 : length(x)
txt = ['$\alpha_1$ = ',num2str(le(1,i))];
plot(x, y, '-+','LineWidth',1.5,'DisplayName',txt);
hold on
end
legend('Location','best','Interpreter','latex','FontSize',16)
legend show
legend boxoff
hold on
xline(1)
xline(10)
grid on
set(gca,'fontweight','bold','FontSize',20)

Respuesta aceptada

Star Strider
Star Strider el 17 de Nov. de 2022
Editada: Star Strider el 17 de Nov. de 2022
Add a patch call —
figure
le=[1,2,3];
x=[0 5 15];
y=2*x;
for i =1 : length(x)
txt = ['$\alpha_1$ = ',num2str(le(1,i))];
hp1{i} = plot(x, y, '-+','LineWidth',1.5,'DisplayName',txt);
hold on
end
hold on
xlinelocs = [1 10];
hxl = xline(xlinelocs);
hp2 = patch([xlinelocs flip(xlinelocs)], [[1 1]*min(ylim) [1 1]*max(ylim)], 'b', 'FaceAlpha',0.25);
hp2.FaceColor = [1 1 1]*0.75;
grid on
set(gca,'fontweight','bold','FontSize',20)
legend([hp1{:}],'Location','best','Interpreter','latex','FontSize',16)
legend show
legend boxoff
Add or modify the patch parameters to get the desired result.
EDIT — Repositioned the legend call.
.
  2 comentarios
Miraboreasu
Miraboreasu el 17 de Nov. de 2022
The patch is not flixeable with different data
Star Strider
Star Strider el 17 de Nov. de 2022
The patch call should work, regardless of what else is plotted with it.
I do not understand the problem you are having with it, and what needs to be fixed.
Please post your code and how you want the plot to appear.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by