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

8 ビュー (過去 30 日間)
Miraboreasu 2022 年 11 月 17 日
コメント済み: Star Strider 2022 年 11 月 17 日
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)

サインインしてコメントする。

採用された回答

Star Strider 2022 年 11 月 17 日

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 件のコメントなしを表示なしを非表示
Miraboreasu 2022 年 11 月 17 日
The patch is not flixeable with different data
Star Strider 2022 年 11 月 17 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by