3

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

4

4 回答 4

6

我遇到了同样的问题。我正在使用 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-07-05T20:09:59.623 回答
1

我卸载了 2.2.2 版matplotlib并安装了 .1.1.2 版marplotlib。我现在可以做put.show()

于 2018-05-01T02:17:50.100 回答
1

进入文件“C:\xampp7\Python\lib\site-packages\pybinding\support\collections.py”并将命令行修改为:“from matplotlib.collections import Collection#, allow_rasterization from matplotlib.artist import allow_rasterization”

于 2018-05-26T08:36:42.820 回答
1

进入目录:~/miniconda3/lib/python3.7/site-packages/pybinding/support

在文件中:collections.py 更改第 2 行:

from matplotlib.collections import Collection, allow_rasterization

from matplotlib.collections import Collection 
from matplotlib.artist import allow_rasterization
于 2019-07-02T12:21:30.303 回答