How do I create two legends in one GScatter Plot?

10 visualizzazioni (ultimi 30 giorni)
Tanja Dorst
Tanja Dorst il 5 Ago 2020
Risposto: G A il 5 Ago 2020
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')

Risposte (1)

G A
G A il 5 Ago 2020
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

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by