@@ -1,144 +1,161 @@
 # Tutorial 2.4.2. Closed systems
 # ==============================
 #
 # Physics background
 # ------------------
 #  Fock-darwin spectrum of a quantum dot (energy spectrum in
 #  as a function of a magnetic field)
 #
 # Kwant features highlighted
 # --------------------------
 #  - Use of `hamiltonian_submatrix` in order to obtain a Hamiltonian
 #    matrix.
 
+import _defs
 from cmath import exp
 import numpy as np
 import kwant
 
 # For eigenvalue computation
 #HIDDEN_BEGIN_tibv
 import scipy.sparse.linalg as sla
 #HIDDEN_END_tibv
 
 # For plotting
 from matplotlib import pyplot
 
 
 def make_system(a=1, t=1.0, r=10):
     # Start with an empty tight-binding system and a single square lattice.
     # `a` is the lattice constant (by default set to 1 for simplicity).
 
 #HIDDEN_BEGIN_qlyd
     lat = kwant.lattice.square(a, norbs=1)
 
     syst = kwant.Builder()
 
     # Define the quantum dot
     def circle(pos):
         (x, y) = pos
         rsq = x ** 2 + y ** 2
         return rsq < r ** 2
 
     def hopx(site1, site2, B):
         # The magnetic field is controlled by the parameter B
         y = site1.pos[1]
         return -t * exp(-1j * B * y)
 
     syst[lat.shape(circle, (0, 0))] = 4 * t
     # hoppings in x-direction
     syst[kwant.builder.HoppingKind((1, 0), lat, lat)] = hopx
     # hoppings in y-directions
     syst[kwant.builder.HoppingKind((0, 1), lat, lat)] = -t
 
     # It's a closed system for a change, so no leads
     return syst
 #HIDDEN_END_qlyd
 
 
 #HIDDEN_BEGIN_yvri
 def plot_spectrum(syst, Bfields):
 
     energies = []
     for B in Bfields:
         # Obtain the Hamiltonian as a sparse matrix
         ham_mat = syst.hamiltonian_submatrix(params=dict(B=B), sparse=True)
 
         # we only calculate the 15 lowest eigenvalues
         ev = sla.eigsh(ham_mat.tocsc(), k=15, sigma=0,
                        return_eigenvectors=False)
 
         energies.append(ev)
 
-    pyplot.figure()
+    fig = pyplot.figure()
     pyplot.plot(Bfields, energies)
-    pyplot.xlabel("magnetic field [arbitrary units]")
-    pyplot.ylabel("energy [t]")
-    pyplot.show()
+    pyplot.xlabel("magnetic field [arbitrary units]",
+                  fontsize=_defs.mpl_label_size)
+    pyplot.ylabel("energy [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(),
+                fontsize=_defs.mpl_tick_size)
+    fig.set_size_inches(_defs.mpl_width_in, _defs.mpl_width_in * 3. / 4.)
+    fig.subplots_adjust(left=0.15, right=0.95, top=0.95, bottom=0.15)
+    for extension in ('pdf', 'png'):
+        fig.savefig("closed_system_result." + extension, dpi=_defs.dpi)
 #HIDDEN_END_yvri
 
 def sorted_eigs(ev):
     evals, evecs = ev
     evals, evecs = map(np.array, zip(*sorted(zip(evals, evecs.transpose()))))
     return evals, evecs.transpose()
 
 #HIDDEN_BEGIN_wave
 def plot_wave_function(syst, B=0.001):
+    size = (_defs.figwidth_in, _defs.figwidth_in)
+
     # Calculate the wave functions in the system.
     ham_mat = syst.hamiltonian_submatrix(sparse=True, params=dict(B=B))
     evals, evecs = sorted_eigs(sla.eigsh(ham_mat.tocsc(), k=20, sigma=0))
 
     # Plot the probability density of the 10th eigenmode.
-    kwant.plotter.map(syst, np.abs(evecs[:, 9])**2,
-                      colorbar=False, oversampling=1)
+    for extension in ('pdf', 'png'):
+        kwant.plotter.map(
+            syst, np.abs(evecs[:, 9])**2, colorbar=False, oversampling=1,
+            file="closed_system_eigenvector." + extension,
+            fig_size=size, dpi=_defs.dpi)
 #HIDDEN_END_wave
 
 
 #HIDDEN_BEGIN_current
 def plot_current(syst, B=0.001):
+    size = (_defs.figwidth_in, _defs.figwidth_in)
+
     # Calculate the wave functions in the system.
     ham_mat = syst.hamiltonian_submatrix(sparse=True, params=dict(B=B))
     evals, evecs = sorted_eigs(sla.eigsh(ham_mat.tocsc(), k=20, sigma=0))
 
     # Calculate and plot the local current of the 10th eigenmode.
     J = kwant.operator.Current(syst)
     current = J(evecs[:, 9], params=dict(B=B))
-    kwant.plotter.current(syst, current, colorbar=False)
+    for extension in ('pdf', 'png'):
+        kwant.plotter.current(
+            syst, current, colorbar=False,
+            file="closed_system_current." + extension,
+            fig_size=size, dpi=_defs.dpi)
 #HIDDEN_END_current
 
 
 def main():
     syst = make_system()
 
-    # Check that the system looks as intended.
-    kwant.plot(syst)
-
     # Finalize the system.
     syst = syst.finalized()
 
     # The following try-clause can be removed once SciPy 0.9 becomes uncommon.
     try:
         # We should observe energy levels that flow towards Landau
         # level energies with increasing magnetic field.
         plot_spectrum(syst, [iB * 0.002 for iB in range(100)])
 
         # Plot an eigenmode of a circular dot. Here we create a larger system for
         # better spatial resolution.
         syst = make_system(r=30).finalized()
         plot_wave_function(syst)
         plot_current(syst)
     except ValueError as e:
         if e.message == "Input matrix is not real-valued.":
             print("The calculation of eigenvalues failed because of a bug in SciPy 0.9.")
             print("Please upgrade to a newer version of SciPy.")
         else:
             raise
 
 
 # Call the main function if the script gets executed (as opposed to imported).
 # See <http://docs.python.org/library/__main__.html>.
 if __name__ == '__main__':
     main()
