diff --git a/doc/source/images/band_structure.py.diff b/doc/source/images/band_structure.py.diff index a7585168982f4a2008e5215ed2742843b0137cf3..3b72444cdc6043c7e26445f6b4d376c0fcc093b2 100644 --- a/doc/source/images/band_structure.py.diff +++ b/doc/source/images/band_structure.py.diff @@ -1,26 +1,25 @@ --- original +++ modified -@@ -12,6 +12,7 @@ +@@ -10,6 +10,7 @@ - # For plotting + # For plotting. from matplotlib import pyplot +import _defs - def make_lead(a=1, t=1.0, W=10): -@@ -38,11 +39,19 @@ - bands = kwant.physics.Bands(lead) - energies = [bands(k) for k in momenta] + # Start with an empty lead with a single square lattice +@@ -33,10 +34,19 @@ -- pyplot.figure() -+ fig = pyplot.figure() - pyplot.plot(momenta, energies) -- pyplot.xlabel("momentum [in units of (lattice constant)^-1]") -- pyplot.ylabel("energy [in units of t]") + def main(): + lead = make_lead().finalized() +- kwant.plotter.bands(lead, show=False) +- pyplot.xlabel("momentum in units of inverse lattice constant") +- pyplot.ylabel("energy in units of t") - pyplot.show() -+ pyplot.xlabel("momentum [in units of (lattice constant)^-1]", ++ fig = kwant.plotter.bands(lead, show=False) ++ pyplot.xlabel("momentum in units of inverse lattice constant", + fontsize=_defs.mpl_label_size) -+ pyplot.ylabel("energy [in units of t]", fontsize=_defs.mpl_label_size) ++ pyplot.ylabel("energy in units of t", fontsize=_defs.mpl_label_size) + pyplot.setp(fig.get_axes()[0].get_xticklabels(), + fontsize=_defs.mpl_tick_size) + pyplot.setp(fig.get_axes()[0].get_yticklabels(), @@ -29,6 +28,7 @@ + fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15) + fig.savefig("band_structure_result.pdf") + fig.savefig("band_structure_result.png", dpi=_defs.dpi) ++ - def main(): + # Call the main function if the script gets executed (as opposed to imported). diff --git a/doc/source/images/superconductor_band_structure.py.diff b/doc/source/images/superconductor_band_structure.py.diff index 8fa888ba89672bb0a32c013e31f0b7a097fe8604..2590026c9a158c70f547e974ea25087763d5ce89 100644 --- a/doc/source/images/superconductor_band_structure.py.diff +++ b/doc/source/images/superconductor_band_structure.py.diff @@ -8,13 +8,13 @@ tau_x = tinyarray.array([[0, 1], [1, 0]]) tau_z = tinyarray.array([[1, 0], [0, -1]]) -@@ -46,12 +47,19 @@ - bands = kwant.physics.Bands(lead) - energies = [bands(k) for k in momenta] +@@ -46,11 +47,19 @@ + # Make system and finalize it right away. + lead = make_lead().finalized() -- pyplot.figure() -+ fig = pyplot.figure() - pyplot.plot(momenta, energies) +- kwant.plotter.bands(lead, momenta=np.linspace(-1.5, 1.5, 101), show=False) ++ fig = kwant.plotter.bands(lead, momenta=np.linspace(-1.5, 1.5, 101), ++ show=False) pyplot.xlabel("momentum [in untis of (lattice constant)^-1]") pyplot.ylabel("energy [in units of t]") pyplot.ylim([-0.8, 0.8]) @@ -29,4 +29,4 @@ + fig.savefig("superconductor_band_structure_result.png", dpi=_defs.dpi) - def main(): + # Call the main function if the script gets executed (as opposed to imported). diff --git a/doc/source/reference/kwant.plotter.rst b/doc/source/reference/kwant.plotter.rst index 0ffcae77e9671cd446aa4664ffbc4c6e9dec2cae..729d9fc0c606463c81aa88a60887b03e8bc8ad72 100644 --- a/doc/source/reference/kwant.plotter.rst +++ b/doc/source/reference/kwant.plotter.rst @@ -11,6 +11,7 @@ Plotting routine plot map + bands Data-generating functions ------------------------- diff --git a/doc/source/tutorial/band_structure.py b/doc/source/tutorial/band_structure.py index 012d14fbbaed0ba03d461efa4d18bf415c98d111..2ad2e3dbe22e3713e814a36cad0abcd039701802 100644 --- a/doc/source/tutorial/band_structure.py +++ b/doc/source/tutorial/band_structure.py @@ -8,12 +8,9 @@ import kwant -from math import pi - -# For plotting +# For plotting. from matplotlib import pyplot - #HIDDEN_BEGIN_zxip def make_lead(a=1, t=1.0, W=10): # Start with an empty lead with a single square lattice @@ -37,24 +34,12 @@ def make_lead(a=1, t=1.0, W=10): #HIDDEN_BEGIN_pejz -def plot_bandstructure(lead, momenta): - bands = kwant.physics.Bands(lead) - energies = [bands(k) for k in momenta] - - pyplot.figure() - pyplot.plot(momenta, energies) - pyplot.xlabel("momentum [in units of (lattice constant)^-1]") - pyplot.ylabel("energy [in units of t]") - pyplot.show() - - def main(): lead = make_lead().finalized() - - # list of momenta at which the bands should be computed - momenta = [-pi + 0.02 * pi * i for i in xrange(101)] - - plot_bandstructure(lead, momenta) + kwant.plotter.bands(lead, show=False) + pyplot.xlabel("momentum in units of inverse lattice constant") + pyplot.ylabel("energy in units of t") + pyplot.show() #HIDDEN_END_pejz diff --git a/doc/source/tutorial/superconductor_band_structure.py b/doc/source/tutorial/superconductor_band_structure.py index 816c32f163f512950e7912e9b9a207d0a586971e..6bed20b2d61809813bad9c5f9fb5b93f636b6f8f 100644 --- a/doc/source/tutorial/superconductor_band_structure.py +++ b/doc/source/tutorial/superconductor_band_structure.py @@ -44,28 +44,17 @@ def make_lead(a=1, t=1.0, mu=0.7, Delta=0.1, W=10): #HIDDEN_END_nbvn -def plot_bandstructure(lead, momenta): - bands = kwant.physics.Bands(lead) - energies = [bands(k) for k in momenta] +def main(): + # Make system and finalize it right away. + lead = make_lead().finalized() - pyplot.figure() - pyplot.plot(momenta, energies) + kwant.plotter.bands(lead, momenta=np.linspace(-1.5, 1.5, 101), show=False) pyplot.xlabel("momentum [in untis of (lattice constant)^-1]") pyplot.ylabel("energy [in units of t]") pyplot.ylim([-0.8, 0.8]) pyplot.show() -def main(): - # Make system and finalize it right away. - lead = make_lead().finalized() - - # list of momenta at which the bands should be computed - momenta = np.linspace(-1.5, 1.5, 201) - - plot_bandstructure(lead, momenta) - - # Call the main function if the script gets executed (as opposed to imported). # See <http://docs.python.org/library/__main__.html>. if __name__ == '__main__': diff --git a/doc/source/tutorial/tutorial3.rst b/doc/source/tutorial/tutorial3.rst index f5b603fa8ace912334efcc2ba4e7e5efcb057590..8c901a1be7dd03936f37248c549759953414d3d7 100644 --- a/doc/source/tutorial/tutorial3.rst +++ b/doc/source/tutorial/tutorial3.rst @@ -31,11 +31,11 @@ contained implicitly finalized versions of the attached leads. But now we are working with a single lead and there is no scattering region. So we have to finalized the ``Builder`` of our sole lead explicitly. -That finalized lead is then passed to `kwant.physics.Bands`. This -creates an object that behaves just like a function: when called with a -momentum ``k`` as parameter it returns the eigenenergies of the translational -invariant system for that momentum. Computing these eigenenergies for a range -of momenta then yields the bandstructure: +That finalized lead is then passed to `~kwant.plotter.bands`. This function +calculates energies of various bands at a range of momenta and plots the +calculated energies. It is really a convenience function, and if one needs to +do something more profound with the dispersion relation these energies may be +calculated directly. For now we just plot the bandstructure: .. literalinclude:: band_structure.py :start-after: #HIDDEN_BEGIN_pejz