How to hide or delete the legend that is not needed

26 ビュー (過去 30 日間)
Terence
Terence 2021 年 2 月 15 日
コメント済み: Terence 2021 年 2 月 15 日
FYI, please see the attached figure.
My aim is to hide or delete the legend data1, data2 and data3, to be like this figure.
Thanks!
  2 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 2 月 15 日
Share the code you use to create and format your figure.
Terence
Terence 2021 年 2 月 15 日
for it=1
plot(lv,reag(it,:),'color',[0 0.4470 0.7410],'LineWidth',LineWidth, 'DisplayName','Mode 1,Analytical,UD');
end
for it=2
plot(lv,reag(it,:),'color',[0 0.4470 0.7410],'LineWidth',LineWidth);
end
for it=3
plot(lv,reag(it,:),'color',[0.8500 0.3250 0.0980],'LineWidth',LineWidth,'DisplayName','Mode 2,Analytical,UD');
end
for it=4
plot(lv,reag(it,:),'color',[0.8500 0.3250 0.0980],'LineWidth',LineWidth);
end
for it=5
plot(lv,reag(it,:),'color',[0.9290 0.6940 0.1250],'LineWidth',LineWidth,'DisplayName','Mode 3,Analytical,UD');
end
for it=6
plot(lv,reag(it,:),'color',[0.9290 0.6940 0.1250],'LineWidth',LineWidth');
end
lgd = legend;
lgd.NumColumns = 1;
legend('boxoff')

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

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 2 月 15 日
編集済み: Cris LaPierre 2021 年 2 月 15 日
Use line objects as inputs to legend, telling it which lines to include in the legend.
x=1:10;
y=@(x,a)((x-5)/a).^2;
p1 = plot(x,y(x,1),'DisplayName','Mode 1,Analytical,UD');
hold on
plot(x,y(x,1.1));
p2 = plot(x,y(x,2),'DisplayName','Mode 2,Analytical,UD');
plot(x,y(x,2.2));
p3 = plot(x,y(x,3),'DisplayName','Mode 3,Analytical,UD');
plot(x,y(x,3.3))
hold off
legend([p1,p2,p3])
  1 件のコメント
Terence
Terence 2021 年 2 月 15 日
It works now. Thanks!

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 2 月 15 日
Try getting rid of the for loops, which essentially do nothing:
plot(lv,reag(1,:),'color',[0 0.4470 0.7410],'LineWidth',LineWidth, 'DisplayName','Mode 1,Analytical,UD');
hold on;
plot(lv,reag(2,:),'color',[0 0.4470 0.7410],'LineWidth',LineWidth);
plot(lv,reag(3,:),'color',[0.8500 0.3250 0.0980],'LineWidth',LineWidth,'DisplayName','Mode 2,Analytical,UD');
plot(lv,reag(4,:),'color',[0.8500 0.3250 0.0980],'LineWidth',LineWidth);
plot(lv,reag(5,:),'color',[0.9290 0.6940 0.1250],'LineWidth',LineWidth,'DisplayName','Mode 3,Analytical,UD');
plot(lv,reag(6,:),'color',[0.9290 0.6940 0.1250],'LineWidth',LineWidth');
legend({'1', '2', '3', '4', '5', '6'})

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by