Search code examples
pythonpybinding

pybinding cannot import name allow_rasterization


I just install pybinding and I'm trying to run the first example that is proposed in the documentation of this library.

import pybinding as pb
import numpy as np
import matplotlib.pyplot as plt
import pybinding as pb

d = 0.2  # [nm] unit cell length
t = 1    # [eV] hopping energy

# create a simple 2D lattice with vectors a1 and a2
lattice = pb.Lattice(a1=[d, 0], a2=[0, d])
lattice.add_sublattices(
    ('A', [0, 0])  # add an atom called 'A' at position [0, 0]
)
lattice.add_hoppings(
    # (relative_index, from_sublattice, to_sublattice, energy)
    ([0, 1], 'A', 'A', t),
    ([1, 0], 'A', 'A', t)
)

lattice.plot()
plt.show() 

I have already installed what is required in the documentation (for Windows OS) and the sicrpt run pretty well until it has to do the lattice.plot() throwing the following error

Traceback (most recent call last):
  File "prueba.py", line 25, in <module>
    lattice.plot()
  File "C:\xampp7\Python\lib\site-packages\pybinding\lattice.py", line 463, in plot
    axes=axes))
  File "C:\xampp7\Python\lib\site-packages\pybinding\results.py", line 598, in plot
    plot_sites(self.positions, self.sublattices, **props['site'])
  File "C:\xampp7\Python\lib\site-packages\pybinding\system.py", line 285, in plot_sites
    from pybinding.support.collections import CircleCollection
  File "C:\xampp7\Python\lib\site-packages\pybinding\support\collections.py", line 2, in <module>
    from matplotlib.collections import Collection, allow_rasterization
ImportError: cannot import name 'allow_rasterization' 

I have already check and matplotlib is correctly installed (I try some plots recommended in the documentation of matplotlib and worked pretty well). Also a looked for the file collections.py in the pybinding library and the mistake is in the second line

import numpy as np
from matplotlib.collections import Collection, allow_rasterization

And looking at collections.py of the matplolib and searching for 'allow_rasterization' I found the duplicated 6 time the following function

@artist.allow_rasterization
def draw(self, renderer):

I am pretty new at python so I'm don't know if I'm looking at what I should. Thanks in advance


Solution

  • I uninstalled version 2.2.2 of matplotlib and installed version 1.1.2 of marplotlib. I am now able to do put.show()