我只是安装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看看collections.py的allow_rasterization,我发现重复的6倍于下面的函数
@artist.allow_rasterization
def draw(self, renderer):我在python非常新,所以我不知道我是否在看我该做什么。提前感谢
发布于 2018-05-01 02:17:50
我卸载了matplotlib的2.2.2版本,并安装了marplotlib的1.1.2版本。我现在可以做put.show()了
发布于 2018-07-05 20:09:59
我也有同样的问题。我使用的是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。
发布于 2018-05-26 08:36:42
进入文件"C:\xampp7\Python\lib\site-packages\pybinding\support\collections.py“并将命令行修改为:”从matplotlib.collections导入Collection#,从matplotlib.artist导入allow_rasterization修改allow_rasterization“。
https://stackoverflow.com/questions/49949775
复制相似问题