gpt4 book ai didi

python - pybinding 无法导入名称 allow_rasterization

转载 作者:行者123 更新时间:2023-11-28 21:37:15 61 4
gpt4 key购买 nike

我刚刚安装了 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 方面很新,所以我不知道我是否在看我应该看的东西。提前致谢

最佳答案

我遇到了同样的问题。我正在使用 Linux,并且软件包 pybinding 安装在

/usr/lib/python3.6/site-packages/pybinding/support/

修改allow_rasterization模块的导入模块,修改文件colletion.py

/usr/lib/python3.6/site-packages/pybinding/support/colletion.py

第一行来自

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

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

您可以在 matplotlib 1.1.2 上更正与以前版本相关的绘图问题,因为现在 pybinding 包使用 matplotlib 2.2.2

关于python - pybinding 无法导入名称 allow_rasterization,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49949775/

61 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com