我只是安装了 pybinding,我正在尝试运行该库文档中提出的第一个示例。
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()
我已经安装了文档中所需的东西(对于 Windows 操作系统)并且 sicrpt 运行得很好,直到它必须执行 lattice.plot() 抛出以下错误
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'
我已经检查并正确安装了 matplotlib(我尝试了一些 matplotlib 文档中推荐的图并且效果很好)。还在 pybinding 库中查找了文件 collections.py,错误在第二行
import numpy as np
from matplotlib.collections import Collection, allow_rasterization
并查看 matplolib 的 collections.py 并搜索“allow_rasterization”,我发现以下函数重复了 6 次
@artist.allow_rasterization
def draw(self, renderer):
我对python很陌生,所以我不知道我是否在看我应该看的东西。提前致谢