How can I give a location to the text written in Yline type plots , without making it an object?
25 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The values of E1 and E12 and others are overlappting i want E1 to be on left and E12 on right how can i give locations to them
clc;
clear all;
N=6;
t=2.5; %ineV
a=1.42e-10; %inAngstrom
h1=1e-3;
ka=-3.14:h1:3.14;
Txt1 = "YY "; Name = "Z_GNR_N6";
mkdir(Name);
%defineing the self interaction within the unitcell
H0=zeros(12,12);
diag1=t*ones(1,2*N-1);
H0=diag(diag1, 1)+diag(diag1, -1);
%definingH1At a (RHS)of H0
H1=zeros(2*N,2*N);
H1(2,1)=t;
H1(3,4)=t;
H1(6,5)=t;
H1(7,8)=t;
H1(10,9)=t;
H1(11,12)=t;
%defineing H2 at-a (LHS)of H0
H2=transpose(H1);
ep=exp(i*ka);
for j=1:length(ka)
%j
%ka(1,j)
if ka(1,j)==0
zeroKaindex=j;
end
h=H0+H1.*exp(i*ka(1,j))+H2.*exp(-i*ka(1,j));
E=abs(eig(h)); %12x1 collum matrix
E1(1,j)=E(1,1); %taking only the 1st eigen value outof 12
E2(1,j)=E(2,1);%taking only the 2nd eigen value outof 12
E3(1,j)=E(3,1);%taking only the 3rd eigen value outof 12
E4(1,j)=E(4,1);%taking only the 4th eigen value outof 12
E5(1,j)=E(5,1);%taking only the 5th eigen value outof 12
E6(1,j)=E(6,1);%..so on
E7(1,j)=E(7,1);
E8(1,j)=E(8,1);
E9(1,j)=E(9,1);
E10(1,j)=E(10,1);
E11(1,j)=E(11,1);
E12(1,j)=E(12,1);
end
disp("index j where Ka is zero: " + zeroKaindex)
The Problem is here !!!!!!!!!!!!
%% Plot of Band diagram
figure(1)
hold on
grid on;title("Energy values at Ka=0");
yline(E1(1,zeroKaindex),'r','E1')
%% The values of E1 and E12 and others are overlappting i want E1 to be on left and E12 on right how can i give locations to them
yline(E2(1,zeroKaindex),'g','E2')
yline(E3(1,zeroKaindex),'b','E3')
yline(E4(1,zeroKaindex),'k','E4')
yline(E5(1,zeroKaindex),'--r','E5')
yline(E6(1,zeroKaindex),'--g','E6')
yline(E7(1,zeroKaindex),'b--','E7')
yline(E8(1,zeroKaindex),'-.g','E8')
yline(E9(1,zeroKaindex),'.c','E9')
yline(E10(1,zeroKaindex),'--c','E10')
yline(E11(1,zeroKaindex),'-.k','E11')
yline(E12(1,zeroKaindex),'-.g','E12')
bandgap=E1(1,zeroKaindex)-E12(1,zeroKaindex);
disp("Band Gap for N= "+N+ " is " + bandgap +"eV")
axes = gca;
axes.LineWidth=0.75; axes.FontSize=15; axes.FontWeight='bold';axes.Box='on';
lines = axes.Children;
set(lines,'LineWidth', 2);
h1=gca;
Txt2 = Txt1 + h1.Title.String + ".png";
saveas(gcf , fullfile(Name, Txt2));
figure(2)
hold on; grid on;title("BAND diagram");
plot(ka,E1,'-', 'Color', [0.75, 0.25, 0.5]);
plot(ka,E2,'-.','MarkerSize',2, 'Color', [0, 0, 1]);
plot(ka,E3,':','MarkerSize',2, 'Color', [0.75, 0.25, 0.5]);
plot(ka,E4,'-','MarkerSize',2, 'Color', [0, 1, 0]);
plot(ka,E5,'-.','MarkerSize',2, 'Color', [0, 0, .3]);
plot(ka,E6,':','MarkerSize',2, 'Color', [0, 1, 1]);
plot(ka,E7,'-','MarkerSize',2, 'Color', [1, 0, 1]);
plot(ka,E8,'-.','MarkerSize',2, 'Color', [0.25, 1, 1]);
plot(ka,E9,'-.','MarkerSize',2, 'Color', [0 0.3882 0.5804]);
plot(ka,E10,'-','MarkerSize',2, 'Color', [1, .25, .25]);
plot(ka,E11,'-','MarkerSize',2, 'Color', [0.7, 0.9, 0.3]);
plot(ka,E12,'--','MarkerSize',2, 'Color', [0.3, 0.5, 0.7]);
xlabel('ka');
ylabel('energy E in eV');
legend('E1','E2','E3','E4','E5','E6','E7','E8','E9','E10','E11','E12')
axes = gca;
axes.LineWidth=0.75; axes.FontSize=15; axes.FontWeight='bold';axes.Box='on';
lines = axes.Children;
set(lines,'LineWidth', 1);
h1=gca;
Txt2 = Txt1 + h1.Title.String + ".png";
saveas(gcf , fullfile(Name, Txt2));
0 commentaires
Réponses (1)
Adam Danz
le 24 Avr 2023
You can specify which side of the axes the label is printed using the LabelHorizontalAlignment property.
Alternatively, you can add space to either side of the label to indent it.
yline(0.8, '-', 'Left', 'LabelHorizontalAlignment', 'left')
yline(0.7, '-', ' Also left', 'LabelHorizontalAlignment', 'left')
yline(.4,'-','Right')
yline(.3,'-','Also right ')
ylim([0,1])
Voir également
Catégories
En savoir plus sur Labels and Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!