function plot_bands!(
BS::BandStructure;
outfile = "tmp.png",
COLOR = recom_color,
SIZE=2.0,
scale_kpath=1.0,
settings=Dict(:colors=>["black",],
:lw=>2.0,
:range=>nothing,
:markerstrokealpha=>0.8,
:markerstrokewidth=>1.0,
:cycle=>true)
)
plt = plot()
color_list = get(settings, :colors, "black" )
line_width = get(settings, :lw , 1.5 )
Ļrange = get(settings, :range , nothing)
#Ī± = get(settings, :markeralpha , 1.0)
MSĪ± = get(settings, :markerstrokealpha , 0.8)
MSw = get(settings, :markerstrokewidth , 1.0)
cycle = get(settings, :cycle , true)
Ncolor = length(color_list)
Nbands = num_bands(BS)
Nop = num_markers(BS)
(Ļmax,Ļmin)= (get_band_max(BS), get_band_min(BS))
bands_k = extract_kpath_to_line(BS,scale=scale_kpath)
KX = vcat((BS.Bands .|> b->get(bands_k,first(b),1.0))...)
YLIM = (Ļrange==nothing ? ((Ļmin-0.05*abs(Ļmin)), (Ļmax+0.05*abs(Ļmax))) : Ļrange)
if cycle
KX = vcat(KX,[KX[end]+abs(KX[end]-KX[end-1]),])
end
basic_settings = (ylims=YLIM, lw=0.5, grid=false, legend=nothing)
# ------------ FRAMES -------------
println("plot_bands!() : plotting frames ...")
frame_settings = (color="gray", basic_settings...)
# horizontal line at en = 0
plt = plot!(KX, 0.0 .* KX; frame_settings...)
# vertical line at high-symmetry point (beginning of each kpath)
vbar = Ļmin .+ ((Ļmax-Ļmin)/20).*collect(0:21)
for band ā BS.Bands
plt = plot!(bands_k[first(band)][1] āØ° 22, vbar; frame_settings...)
end
# right-most vertical border
plt = plot!(KX[end] āØ° 22, vbar; frame_settings...)
# ------------ BANDS -------------
println("plot_bands!() : plotting markers ...")
plt = scatter!( ;
markershape = :circle,
markercolor = :transparent,
legend = nothing )
color_func(x,c) = (real(x)>0.001) ? c : "white"
size_func(x,s) = (real(x)>0.001) ? s*real(x) : 0.0
for n ā 1:Nbands
BAND = vcat([map(x->x[2][n],last(band)) for band ā BS.Bands]...)
if cycle
BAND = vcat(BAND,[BAND[1],])
end
for iop in 1:Nop
markercolor = vcat([ map(x-> color_func(x[2][n,iop], COLOR[iop]), vtkpm)
for (s,vtkpm) ā BS.Markers ]...)
markersize = vcat([ map(x-> size_func(x[2][n,iop], ((SIZE isa Vector) ? SIZE[iop] : SIZE)), vtkpm)
for (s,vtkpm) ā BS.Markers ]...)
plt = scatter!( KX, BAND,
markershape = :circle,
markersize = markersize, ##!!! SIZE MAY BE CLOSE TO ZERO !!!
markercolor = :transparent,
markerstrokealpha = MSĪ±,
markerstrokecolor = markercolor,
markerstrokewidth = MSw,
legend = nothing )
end
end
println("plot_bands!() : plotting lines ...")
BANDS = [vcat([map(x->x[2][n],band) for (s,band) ā BS.Bands]...) for n ā 1:Nbands]
for n ā 1:Nbands
BD = BANDS[n]
if cycle
BD = vcat(BD,[BD[1],])
end
c = Nop==0 ? "black" : color_list[(n-1)%Ncolor+1]
plt = plot!(KX, BD; color=c, basic_settings...)
end
# --------------------------------------
println("plot_bands!() : saving ...")
savefig(plt, outfile)
return outfile
end
Iāve tested that the only slow command is savefig(plt, outfile)
at the end. Other plotting commands are fast.