Author Topic: Plot band structure  (Read 3295 times)

0 Members and 1 Guest are viewing this topic.

Offline davalenciah

  • Heavy QuantumATK user
  • ***
  • Posts: 26
  • Reputation: 0
    • View Profile
Plot band structure
« on: March 8, 2010, 18:22 »
Hello

I'm calculating the band structure and energy gap.
I want to plot the different band structure in the same graphics and I used the matplotlib as

from NanoLanguage import *
import pylab


y=bandstructure.evaluate()
x=bandstructure.kpoints()
pylab.figure()
pylab.plot(x,y)

but it did in a wrong way
could someone help me to plot different  band structures in a same graph

Thanks
 
« Last Edit: March 8, 2010, 18:24 by davalenciah »

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5413
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: Plot band structure
« Reply #1 on: March 8, 2010, 21:05 »
There's a small trick to it, but it's fortunately pretty straightforward ;) Assuming we have two (at least) band structures in the same NetCDF file ("file.nc"), I hope this script is self-explanatory:
Code
from NanoLanguage import *
import pylab as P

# Colors for each band structure (add more if you have more than 4 band structures in the file)
colors = ['r','b','g','m']

bandstructures = nlread("file.nc", Bandstructure)
for i,bs in enumerate(bandstructures):
    P.plot(bs._axisGUI(), bs.evaluate(), colors[i])
P.savefig("plot.png")
Here's a more advanced version, which allows you to set the limits of the energy axis (often needed) and include the route labels.
Code
from NanoLanguage import *
import pylab as P

# Parameters
ncfile = 'file.nc'
plotfile = 'plot.png'
ymin = -10
ymax = 10
# Colors for each band structure (add more if you have more than 4 band structures in the file)
colors = ['r','b','g','m']

bandstructures = nlread(ncfile, Bandstructure)

for i,bs in enumerate(bandstructures):
    P.plot(bs._axisGUI(), bs.evaluate(), colors[i])

# Set x-ticks = the symmetry points
kticks = [ tick[0] for tick in bs._ticksGUI() ]
ticklabels = [ tick[1].replace('Γ','$\Gamma$') for tick in bs._ticksGUI() ]
P.xticks(kticks,ticklabels)

P.grid(kticks)
P.ylim(ymin,ymax)

P.savefig(plotfile)
« Last Edit: March 8, 2010, 21:07 by Anders Blom »