# How can I plot a diagram with 12-15 different colors

43 views (last 30 days)
Subham Mahanti on 24 Apr 2023
Commented: Subham Mahanti on 24 Apr 2023
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
zeroKaindex = 3141
%% 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')
Warning: Marker input is ignored.
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)
bandgap_in_eV = 0.6262
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);
Stephen23 on 24 Apr 2023
"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.:
Subham Mahanti on 24 Apr 2023
Okay , but how to do that in this context , i mean how to incorporate that into my plot , if there is any alternate easier way then also suggest

Alan Stevens on 24 Apr 2023
Specify the colors with RGB triplets.
doc Color
Steven Lord on 24 Apr 2023
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)
Subham Mahanti on 24 Apr 2023
Yes got it Thank you everyone !