Hello,

When trying to use kwant with matplotlib 1.4.0 (which is the last released version), I had a problem when trying to draw a system. For exemple, the following code

import kwant
import matplotlib as mpl
import matplotlib.pyplot as plt
%matplotlib inline # to be used in ipython notebook
lat = kwant.lattice.square(1.)
sys = kwant.Builder()
sys[(lat(x, y) for x in xrange(20) for y in xrange(10))] = 1.
sys[lat.neighbors(1)] = 1.
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
lead[(lat(0, y) for y in xrange(10))] = 1.
sys.attach_lead(lead)
sys.attach_lead(lead.reversed())
p = kwant.plot(sys, show=False)
plt.show()

produces a huge traceback ending with

ValueError: Transforms must be a Nx3x3 numpy array

The exact result depends on the matplotlib backend, but when an image is produced, the sites of the leads are not drawn.

The bug seems to come from an update in matplotlib API, and is (in this case) fixed by changing line 94 of plotter.py (http://git.kwant-project.org/kwant/tree/kwant/plotter.py#n94) from

self._transforms = [matplotlib.transforms.Affine2D().scale(x) for x in sizes]

to

self._transforms = [matplotlib.transforms.Affine2D().scale(x).get_matrix() for x in sizes]

There may be other instances of this in kwant, but fixing this one is enough to make the previous code work. A similar issue in 3D is described in https://www.mail-archive.com/[email protected]/msg00111.html (I did not look further into this one.)

Best,

Michel

Reply via email to