How do I create two legends in one GScatter Plot?

25 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Legend 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by