Skip to content
Snippets Groups Projects
Commit ca63f1d8 authored by Joseph Weston's avatar Joseph Weston
Browse files

add matplotlib boilerplate to start of all tutorials

Currently we just set the default figure size. Matplotlib is
annoying when it comes to setting these default parameters, and we
have to ensure that we set any 'rcParams' in a separate Jupyter cell
and *after* we import pyplot.
parent 9eb71bb3
No related branches found
No related tags found
No related merge requests found
...@@ -52,6 +52,9 @@ a quantum anomalous spin Hall phase: ...@@ -52,6 +52,9 @@ a quantum anomalous spin Hall phase:
import kwant import kwant
import kwant.continuum import kwant.continuum
.. jupyter-execute:: ../../tutorial/boilerplate.py
:hide-code:
.. jupyter-execute:: .. jupyter-execute::
def make_model(a): def make_model(a):
......
import matplotlib
import matplotlib.pyplot
from IPython.display import set_matplotlib_formats
matplotlib.rcParams['figure.figsize'] = matplotlib.pyplot.figaspect(1) * 2
set_matplotlib_formats('svg')
...@@ -42,6 +42,9 @@ continuum models and for discretizing them into tight-binding models. ...@@ -42,6 +42,9 @@ continuum models and for discretizing them into tight-binding models.
import kwant import kwant
.. jupyter-execute:: boilerplate.py
:hide-code:
.. _tutorial_discretizer_introduction: .. _tutorial_discretizer_introduction:
Discretizing by hand Discretizing by hand
......
...@@ -14,6 +14,9 @@ into Kwant's structure. ...@@ -14,6 +14,9 @@ into Kwant's structure.
import matplotlib import matplotlib
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
.. jupyter-execute:: boilerplate.py
:hide-code:
What is a system, and what is a builder? What is a system, and what is a builder?
======================================== ========================================
A Kwant system represents a particular tight-binding model. It contains a graph A Kwant system represents a particular tight-binding model. It contains a graph
......
...@@ -88,6 +88,9 @@ In order to use Kwant, we need to import it: ...@@ -88,6 +88,9 @@ In order to use Kwant, we need to import it:
# For plotting # For plotting
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
.. jupyter-execute:: .. jupyter-execute::
import kwant import kwant
...@@ -452,6 +455,11 @@ file and defining the a square lattice and empty scattering region. ...@@ -452,6 +455,11 @@ file and defining the a square lattice and empty scattering region.
# For plotting # For plotting
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
.. jupyter-execute::
a = 1 a = 1
t = 1.0 t = 1.0
W, L = 10, 30 W, L = 10, 30
...@@ -661,6 +669,11 @@ return a Kwant ``Builder``: ...@@ -661,6 +669,11 @@ return a Kwant ``Builder``:
from matplotlib import pyplot from matplotlib import pyplot
import kwant import kwant
.. jupyter-execute:: boilerplate.py
:hide-code:
.. jupyter-execute::
def make_system(L, W, a=1, t=1.0): def make_system(L, W, a=1, t=1.0):
lat = kwant.lattice.square(a) lat = kwant.lattice.square(a)
......
...@@ -47,6 +47,9 @@ explicitly here to show how to define a new lattice: ...@@ -47,6 +47,9 @@ explicitly here to show how to define a new lattice:
sin_30, cos_30 = (1 / 2, sqrt(3) / 2) sin_30, cos_30 = (1 / 2, sqrt(3) / 2)
.. jupyter-execute:: boilerplate.py
:hide-code:
.. jupyter-execute:: .. jupyter-execute::
graphene = kwant.lattice.general([(1, 0), (sin_30, cos_30)], graphene = kwant.lattice.general([(1, 0), (sin_30, cos_30)],
......
...@@ -39,6 +39,9 @@ KPM method `kwant.kpm`, that is based on the algorithms presented in Ref. [1]_. ...@@ -39,6 +39,9 @@ KPM method `kwant.kpm`, that is based on the algorithms presented in Ref. [1]_.
import scipy import scipy
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
Introduction Introduction
************ ************
...@@ -151,7 +154,7 @@ We start by importing kwant and defining our system. ...@@ -151,7 +154,7 @@ We start by importing kwant and defining our system.
# Plot several density of states curves on the same axes. # Plot several density of states curves on the same axes.
def plot_dos(labels_to_data): def plot_dos(labels_to_data):
pyplot.figure(figsize=(5,4)) pyplot.figure()
for label, (x, y) in labels_to_data: for label, (x, y) in labels_to_data:
pyplot.plot(x, y.real, label=label, linewidth=2) pyplot.plot(x, y.real, label=label, linewidth=2)
pyplot.legend(loc=2, framealpha=0.5) pyplot.legend(loc=2, framealpha=0.5)
...@@ -162,7 +165,7 @@ We start by importing kwant and defining our system. ...@@ -162,7 +165,7 @@ We start by importing kwant and defining our system.
# Plot fill density of states plus curves on the same axes. # Plot fill density of states plus curves on the same axes.
def plot_dos_and_curves(dos, labels_to_data): def plot_dos_and_curves(dos, labels_to_data):
pyplot.figure(figsize=(5,4)) pyplot.figure()
pyplot.fill_between(dos[0], dos[1], label="DoS [a.u.]", pyplot.fill_between(dos[0], dos[1], label="DoS [a.u.]",
alpha=0.5, color='gray') alpha=0.5, color='gray')
for label, (x, y) in labels_to_data: for label, (x, y) in labels_to_data:
......
...@@ -51,6 +51,9 @@ texture. ...@@ -51,6 +51,9 @@ texture.
# letters denote spinor indices # letters denote spinor indices
sigma = np.rollaxis(np.array([sigma_x, sigma_y, sigma_z]), 1) sigma = np.rollaxis(np.array([sigma_x, sigma_y, sigma_z]), 1)
.. jupyter-execute:: boilerplate.py
:hide-code:
Introduction Introduction
------------ ------------
Our starting point will be the following spinful tight-binding model on Our starting point will be the following spinful tight-binding model on
......
...@@ -35,6 +35,9 @@ these options can be used to achieve various very different objectives. ...@@ -35,6 +35,9 @@ these options can be used to achieve various very different objectives.
import kwant import kwant
.. jupyter-execute:: boilerplate.py
:hide-code:
We begin by first considering a circular graphene quantum dot (similar to what We begin by first considering a circular graphene quantum dot (similar to what
has been used in parts of the tutorial :ref:`tutorial-graphene`.) In contrast has been used in parts of the tutorial :ref:`tutorial-graphene`.) In contrast
to previous examples, we will also use hoppings beyond next-nearest neighbors: to previous examples, we will also use hoppings beyond next-nearest neighbors:
...@@ -216,6 +219,9 @@ visible. The hoppings are also plotted in order to show the underlying lattice. ...@@ -216,6 +219,9 @@ visible. The hoppings are also plotted in order to show the underlying lattice.
import kwant import kwant
.. jupyter-execute:: boilerplate.py
:hide-code:
Zincblende is a very common crystal structure of semiconductors. It is a Zincblende is a very common crystal structure of semiconductors. It is a
face-centered cubic crystal with two inequivalent atoms in the unit cell face-centered cubic crystal with two inequivalent atoms in the unit cell
(i.e. two different types of atoms, unlike diamond which has the same crystal (i.e. two different types of atoms, unlike diamond which has the same crystal
......
...@@ -30,6 +30,9 @@ Band structure calculations ...@@ -30,6 +30,9 @@ Band structure calculations
# For plotting # For plotting
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
When doing transport simulations, one also often needs to know the band When doing transport simulations, one also often needs to know the band
structure of the leads, i.e. the energies of the propagating plane waves in the structure of the leads, i.e. the energies of the propagating plane waves in the
leads as a function of momentum. This band structure contains information about leads as a function of momentum. This band structure contains information about
...@@ -137,6 +140,9 @@ Closed systems ...@@ -137,6 +140,9 @@ Closed systems
from matplotlib import pyplot from matplotlib import pyplot
import kwant import kwant
.. jupyter-execute:: boilerplate.py
:hide-code:
Although Kwant is (currently) mainly aimed towards transport problems, it Although Kwant is (currently) mainly aimed towards transport problems, it
can also easily be used to compute properties of closed systems -- after can also easily be used to compute properties of closed systems -- after
all, a closed system is nothing more than a scattering region without leads! all, a closed system is nothing more than a scattering region without leads!
......
...@@ -68,6 +68,9 @@ for small arrays.) ...@@ -68,6 +68,9 @@ for small arrays.)
# For plotting # For plotting
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
.. jupyter-execute:: .. jupyter-execute::
# For matrix support # For matrix support
...@@ -242,6 +245,9 @@ Spatially dependent values through functions ...@@ -242,6 +245,9 @@ Spatially dependent values through functions
# For plotting # For plotting
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
Up to now, all examples had position-independent matrix-elements Up to now, all examples had position-independent matrix-elements
(and thus translational invariance along the wire, which (and thus translational invariance along the wire, which
was the origin of the conductance steps). Now, we consider the was the origin of the conductance steps). Now, we consider the
...@@ -403,6 +409,9 @@ Nontrivial shapes ...@@ -403,6 +409,9 @@ Nontrivial shapes
# For plotting # For plotting
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
Up to now, we only dealt with simple wire geometries. Now we turn to the case Up to now, we only dealt with simple wire geometries. Now we turn to the case
of a more complex geometry, namely transport through a quantum ring of a more complex geometry, namely transport through a quantum ring
that is pierced by a magnetic flux :math:`\Phi`: that is pierced by a magnetic flux :math:`\Phi`:
...@@ -594,6 +603,12 @@ period of one flux quantum. ...@@ -594,6 +603,12 @@ period of one flux quantum.
import kwant import kwant
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
.. jupyter-execute::
:hide-code:
a = 1 a = 1
t = 1.0 t = 1.0
W = 10 W = 10
...@@ -643,6 +658,12 @@ period of one flux quantum. ...@@ -643,6 +658,12 @@ period of one flux quantum.
import kwant import kwant
from matplotlib import pyplot from matplotlib import pyplot
.. jupyter-execute:: boilerplate.py
:hide-code:
.. jupyter-execute::
:hide-code:
a = 1 a = 1
t = 1.0 t = 1.0
W = 10 W = 10
......
...@@ -35,6 +35,9 @@ Superconductors: orbital degrees of freedom, conservation laws and symmetries ...@@ -35,6 +35,9 @@ Superconductors: orbital degrees of freedom, conservation laws and symmetries
tau_y = tinyarray.array([[0, -1j], [1j, 0]]) tau_y = tinyarray.array([[0, -1j], [1j, 0]])
tau_z = tinyarray.array([[1, 0], [0, -1]]) tau_z = tinyarray.array([[1, 0], [0, -1]])
.. jupyter-execute:: boilerplate.py
:hide-code:
This example deals with superconductivity on the level of the This example deals with superconductivity on the level of the
Bogoliubov-de Gennes (BdG) equation. In this framework, the Hamiltonian Bogoliubov-de Gennes (BdG) equation. In this framework, the Hamiltonian
is given as is given as
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment