How do I create two legends in one GScatter Plot?

10 visualizaciones (últimos 30 días)
Tanja Dorst
Tanja Dorst el 5 de Ag. de 2020
Respondida: G A el 5 de Ag. de 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')

Respuestas (1)

G A
G A el 5 de Ag. de 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

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by