我在python 2.7中运行时没有问题,但是当我在python 3中运行时遇到错误.
我需要在此代码中更改某些内容.
import matplotlib as mpl
poly = mpl.path.Path(zip(listx,listy))
Run Code Online (Sandbox Code Playgroud)
我得到的错误是
TypeError: float() argument must be a string or a number, not 'zip'
Run Code Online (Sandbox Code Playgroud)
msv*_*kon 14
这是因为在python2中zip()返回一个mpl.path.Path()愉快接受的元组列表.在python3中,zip()返回一个必须使用的迭代器.你应该可以这样做:
>>> poly = mpl.path.Path(list(zip(listx, listy)))
Run Code Online (Sandbox Code Playgroud)