How can I plot a diagram with 12-15 different colors
51 次查看(过去 30 天)
显示 更早的评论
I am plotting this graph and each graph has a different argument (y value) to it, now i want to give all the graphs different colours , how can i do that , if anyone knows please help. (Figure 2 of the Code)
clc;
clear all;
t=2.5; %ineV
a=1.42e-10; %inAngstrom
h1=1e-3;
ka=-3.14:h1:3.14;
%defineing the self interaction within the unitcell
H0=zeros(12,12);
H0(1,2)=t;
H0(2,1)=t;
H0(2,3)=t;
H0(2,5)=t;
H0(3,2)=t;
H0(3,5)=t;
H0(3,8)=t;
H0(4,3)=t;
H0(5,2)=t;
H0(5,6)=t;
H0(6,5)=t;
H0(6,7)=t;
H0(6,9)=t;
H0(7,6)=t;
H0(7,8)=t;
H0(8,3)=t;
H0(8,7)=t;
H0(9,6)=t;
H0(9,10)=t;
H0(10,9)=t;
H0(10,11)=t;
H0(11,10)=t;
H0(11,12)=t;
H0(12,7)=t;
H0(12,11)=t;
%definingH1At a (RHS)of H0
H1=zeros(12,12);
H1(4,1)=t;
H1(8,5)=t;
H1(12,9)=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
%% Plot of Band diagram
figure(1)
hold on
grid on;title("Energy values at Ka=0");
yline(E1(1,zeroKaindex),'r','E1')
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_in_eV=E1(1,zeroKaindex)-E3(1,zeroKaindex)
axes = gca;
axes.LineWidth=0.75; axes.FontSize=15; axes.FontWeight='bold';axes.Box='on';
lines = axes.Children;
set(lines,'LineWidth', 2);
%%this is where i need help
figure(2)
hold on; grid on;title("BAND diagram");
plot(ka,E1, 'r--','LineWidth',0.8);
plot(ka,E2, '-.k','LineWidth',0.8);
plot(ka,E3, '-.g','LineWidth',0.8);
plot(ka,E4, '-.b','LineWidth',0.8);
plot(ka,E5, '-k','LineWidth',0.8);
plot(ka,E6, 'g--','LineWidth',0.8);
plot(ka,E7, '-r','LineWidth',0.8);
plot(ka,E8, '-g','LineWidth',0.8);
plot(ka,E9, '-b','LineWidth',0.8);
plot(ka,E10, '-c','LineWidth',0.8);
plot(ka,E11, '-m','LineWidth',0.8);
plot(ka,E12, 'y--','LineWidth',0.8);
xlabel('ka');
ylabel('energy E in eV');
axes = gca;
axes.LineWidth=0.75; axes.FontSize=15; axes.FontWeight='bold';axes.Box='on';
lines = axes.Children;
set(lines,'LineWidth', 2);
2 个评论
Stephen23
2023-4-24
"now i want to give all the graphs different colours , how can i do that"
You would need to generate 15 different colors, e.g.:
回答(1 个)
Alan Stevens
2023-4-24
Specify the colors with RGB triplets.
doc Color
7 个评论
Steven Lord
2023-4-24
Use uisetcolor. For example I brought up that dialog (using the code I commented out below, since it won't work on MATLAB Answers) and selected a dark-ish pink. It returned a certain vector that I've approximated below.
% c = uisetcolor;
c = [0.9686, 0.5137, 0.7333];
surf(peaks, 'FaceColor', c)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!