trying to create a legend that explains scatter plot marker type
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Tyler Herrington
il 13 Mag 2014
Commentato: Mike Garrity
il 25 Nov 2015
The code below plots the minimum overturning circulation value of the Atlantic Thermohaline Circulation from 24 different simulations as a scatter plot figure, where simulations with the same total emissions are grouped together by colour, but each run is given a different symbol. For example the 'FAST' run from each cumulative emission group is given a '*' symbol, while the instantaneous pulse ('PULSE') runs are given a 'd' (diamond) symbol.
I am trying to create a legend that will explain the symbols used, not the colours used. The legend command gets the first four symbols correct (FAST, VFAST, OVST, and PULSE), but fails to give the correct symbols for MEDIUM and SLOW
(and I think I know why - because the first scatter plot group under h11 only has 4 symbols, so it moves onto the next 2 symbols from h12, which happen to be '*' and 'x', not 'x' and 's'). Does anyone know how to fix the legend, such that it will display the following:
'* FAST 'o' VFAST 'x' MEDIUM 's' SLOW '+' OVST 'd' PULSE
in this particular order?
subplot(2,2,3)
h11 = scatter(MOCmaxCumEmFAST, minMOCFAST,size,clr1,'*');
hold on
scatter(MOCmaxCumEmVFAST, minMOCVFAST,size,clr1,'o');
scatter(MOCmaxCumEmOVST, minMOCOVST,size,clr1,'+');
scatter(MOCmaxCumEmPULSE, minMOCPULSE,size,clr1,'d');
h12 = scatter(MOCmaxCumEmFAST2000, minMOCFAST2000,size,clr2,'*');
scatter(MOCmaxCumEmMEDIUM2000, minMOCMEDIUM2000,size,clr2,'x');
scatter(MOCmaxCumEmSLOW2000, minMOCSLOW2000,size,clr2,'square');
scatter(MOCmaxCumEmOVST2000, minMOCOVST2000,size,clr2,'+');
scatter(MOCmaxCumEmPULSE2000, minMOCPULSE2000,size,clr2,'d');
h13 = scatter(MOCmaxCumEmFAST3000, minMOCFAST3000,size,clr3,'*');
scatter(MOCmaxCumEmMEDIUM3000, minMOCMEDIUM3000,size,clr3,'x');
scatter(MOCmaxCumEmSLOW3000, minMOCSLOW3000,size,clr3,'square');
scatter(MOCmaxCumEmOVST3000, minMOCOVST3000,size,clr3,'+');
scatter(MOCmaxCumEmPULSE3000, minMOCPULSE3000,size,clr3,'d');
h14 = scatter(MOCmaxCumEmFAST4000, minMOCFAST4000,size,clr4,'*');
scatter(MOCmaxCumEmMEDIUM4000, minMOCMEDIUM4000,size,clr4,'x');
scatter(MOCmaxCumEmSLOW4000, minMOCSLOW4000,size,clr4,'square');
scatter(MOCmaxCumEmOVST4000, minMOCOVST4000,size,clr4,'+');
scatter(MOCmaxCumEmPULSE4000, minMOCPULSE4000,size,clr4,'d');
h15 = scatter(MOCmaxCumEmFAST5000, minMOCFAST5000,size,clr5,'*');
scatter(MOCmaxCumEmMEDIUM5000, minMOCMEDIUM5000,size,clr5,'x');
scatter(MOCmaxCumEmSLOW5000, minMOCSLOW5000,size,clr5,'square');
scatter(MOCmaxCumEmOVST5000, minMOCOVST5000,size,clr5,'+');
scatter(MOCmaxCumEmPULSE5000, minMOCPULSE5000,size,clr5,'d');
%title('Peak Response of Maximum Overturning Circulation for the 1000-5000 Gt C scenarios')
set(gca,'FontSize',15,'fontWeight','bold')
set(findall(gcf,'type','text'),'FontSize',15,'fontWeight','bold')
text(500,13.5,'C','FontSize',15,'fontWeight','bold')
xlabel('Cumulative Emissions at time of Peak MOC Response (GtC)')
ylabel('Minimum Overturning (Sv)')
axis([0 6000 12 20])
legend(['*' 'o' '+' 'd' 'x' 'square'],{'FAST', 'VFAST','OVST', 'PULSE','MEDIUM', 'SLOW'});
1 Commento
Jon Camilleri
il 25 Nov 2015
Where do I find parameter documentation in detail as I struggle to understand the examples given in the documentation?
Risposta accettata
Sara
il 13 Mag 2014
You can try changing the order in which you plot data as:
hold on
h11 = scatter(MOCmaxCumEmFAST, minMOCFAST,size,clr1,'*');
scatter(MOCmaxCumEmVFAST, minMOCVFAST,size,clr1,'o');
scatter(MOCmaxCumEmOVST, minMOCOVST,size,clr1,'+');
scatter(MOCmaxCumEmPULSE, minMOCPULSE,size,clr1,'d');
scatter(MOCmaxCumEmMEDIUM2000, minMOCMEDIUM2000,size,clr2,'x');
scatter(MOCmaxCumEmSLOW2000, minMOCSLOW2000,size,clr2,'square');
...more plots
legend({'FAST', 'VFAST','OVST', 'PULSE','MEDIUM', 'SLOW'});
This should give you the right thing.
2 Commenti
Mike Garrity
il 25 Nov 2015
Another good way to do this sort of thing is to keep the handles to the objects and pass them to legend in the order you want:
subplot(2,2,3)
h11 = scatter(MOCmaxCumEmFAST, minMOCFAST,size,clr1,'*');
h_star = h11;
hold on
h_circle = scatter(MOCmaxCumEmVFAST, minMOCVFAST,size,clr1,'o');
h_plus = scatter(MOCmaxCumEmOVST, minMOCOVST,size,clr1,'+');
h_diamond = scatter(MOCmaxCumEmPULSE, minMOCPULSE,size,clr1,'d');
h12 = scatter(MOCmaxCumEmFAST2000, minMOCFAST2000,size,clr2,'*');
h_x = scatter(MOCmaxCumEmMEDIUM2000, minMOCMEDIUM2000,size,clr2,'x');
h_square = scatter(MOCmaxCumEmSLOW2000, ...
minMOCSLOW2000,size,clr2,'square');
% ...
legend([h_star,h_circle,h_plus,h_diamond,h_x,h_square], ...
{'FAST', 'VFAST','OVST', 'PULSE','MEDIUM', 'SLOW'});
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Legend in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!