How do I create two legends in one GScatter Plot?

10 ビュー (過去 30 日間)
Tanja Dorst
Tanja Dorst 2020 年 8 月 5 日
回答済み: G A 2020 年 8 月 5 日
Hi,
so I have two gscatter plots in one figure and I would like to add a a legend for each of the plots. So the problem is, that the first legend is filled with the entries of the second legend at the end. Can someone help me?
Thanks a lot.
figure();
hold on
gs1 = gscatter(data(:,1),data(:,2),target,[],[],20);
leg1 = legend(gs1, 'Location','NorthEastOutside');
title(leg1,'Data1')
gs2 = gscatter(data(:,3),data(:,4),target,[],'o',5);
a=axes('position',get(gca,'position'),'visible','off');
leg2 = legend(a, gs2, 'Location','EastOutside');
title(leg2,'Data2')

回答 (1 件)

G A
G A 2020 年 8 月 5 日
Rearrange your code in the following sequence:
figure();
clf
hold on
gs1 = gscatter(data(:,1),data(:,2),target,[],[],20);
gs2 = gscatter(data(:,3),data(:,4),target,[],'o',5);
a1=gca;
a2=axes('position',get(gca,'position'),'visible','off');
leg1 = legend(a1, gs1, 'Location','NorthEastOutside');
leg2 = legend(a2, gs2, 'Location','EastOutside');
title(leg1,'Data1');
title(leg2,'Data2');
hold off

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by