필터 지우기
필터 지우기

trying to create a legend that explains scatter plot marker type

조회 수: 1 (최근 30일)
Tyler Herrington
Tyler Herrington 2014년 5월 13일
댓글: Mike Garrity 2015년 11월 25일
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
Jon Camilleri
Jon Camilleri 2015년 11월 25일
Where do I find parameter documentation in detail as I struggle to understand the examples given in the documentation?

댓글을 달려면 로그인하십시오.

채택된 답변

Sara
Sara 2014년 5월 13일
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
Mike Garrity
Mike Garrity 2015년 11월 25일
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'});

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by