A bug with kwant and matplotlib 1.4
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/kwant-discuss@kwant-project.org/msg00111.html (I did not look further into this one.) Best, Michel
Dear Michel, thanks for reporting this bug and the fix. In fact we are right now working on fixing kwant to work with matplptlib 1.4. Unfortunately, there is another problem in the 3D plotting that may require more work to fix (https://github.com/matplotlib/matplotlib/issues/3493) Best, Michael On 10.09.2014 14:08, Michel Fruchart wrote:
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/kwant-discuss@kwant-project.org/msg00111.html (I did not look further into this one.)
Best,
Michel
участники (2)
-
Michael Wimmer
-
Michel Fruchart