How to make 2 legends
Afficher commentaires plus anciens
Hey,
I have a code as follows, which find a intersection of my function with y axis on the top and bottom. I would like to make 2 legends: one which corresponds to Temperature (now is creared), and the second which corresponds to the name of the sample, i.e. the type of point corresponds to sample{j} ). Does anybody have any suggestions?
close all
field = [0];
for j = 1:length(folderpath1)
for i = 1:length(specID1{1,j})
if (length(T1{i,j}.data) == 217 || length(T1{i,j}.data) == 237)
[minValue1(i,j),closestindex1N(i,j)] = min( abs( field - (H{i,j}( 1:1:((length(H{i,j})+1)/2)) )' ) ); % 15 kOe to -15 kOe
[minValue2(i,j),closestindex2(i,j)] = min( abs( field - (H{i,j}( ((length(H{i,j})+3)/2):1:end ) )' ) ) ; % -15 kOe to 15 kOe
closestindex2N(i,j) = (closestindex2(i,j) + ((length(H{1,1})+1)/2));
% find values of M for H=0 Oe, i.e. Mr
Mrplus(i,j) = M{i,j}(closestindex1N(i,j),1);
Mrminus(i,j) = abs(M{i,j}(closestindex2N(i,j),1));
Mrmean(i,j) = (Mrplus(i,j) + Mrminus(i,j))/2 ;
if str2double(TempLegend{i,j})==315
if i==1
PColor = [0 100 0]/256;
else
PColor = [0 255 0]/256;
end
elseif str2double(TempLegend{i,j})==80
PColor = 'b';
elseif str2double(TempLegend{i,j})==440
PColor = 'r';
end
if j==1; Point = 'o';
elseif j==2; Point = 's';
elseif j==3; Point = 'p';
elseif j==4; Point = 'd';
elseif j==5; Point = '*';
end
figure(10); grid on; grid minor
if j==2
plt2a(i,j) = plot(str2double(TempLegend{i,j}), Mrmean(i,j), Point,'Color',PColor,'MarkerSize',10,'displayname',[TempLegend{i,j} ' K']); hold on
else
plt2a(i,j) = plot(str2double(TempLegend{i,j}), Mrmean(i,j), Point,'Color',PColor,'MarkerSize',10,'handlevisibility','off'); hold on
end
legend('-DynamicLegend','location','northeast','fontsize',11,'box','off');
hold on; xlim([ 40 480 ]);
ylim([-0.1 2])
grid minor
end
end
end
delete(plt2a(5,2))
Plot looks like that:

Réponse acceptée
Plus de réponses (1)
Nadir Altinbas
le 4 Nov 2019
0 votes
f = field[0]
j = 1:length(folderpath1)
plot(f,folderpath1);
hold on
i = 1:length(specID1{1,j})
plot(j,i)
legend('(i)',('j)')
note that to delete legend legend('off')
to add legend to axis legend(ax1,{'Line 1','Line 2','Line 3'})
legend('-DynamicLegend','location','northeast','fontsize',11,'box','off');
Catégories
En savoir plus sur Legend dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
