无法解压不可迭代的 PathCollection 对象

Om *_*ogi 2 python matplotlib

fig,ax = plt.subplots()
ax.set_xlim(0,500)
ax.set_ylim(0,500)
scatter, = ax.scatter(x_arr,y_arr)
plt.show()
Run Code Online (Sandbox Code Playgroud)

在 scatter 语句中,程序出现了此错误。我不明白可能是什么问题。

---
TypeError                                 Traceback (most recent call last)
<ipython-input-26-b70b84828456> in <module>
      6 ax.set_xlim(0,500)
      7 ax.set_ylim(0,500)
----> 8 scatter, = ax.scatter(x_arr,y_arr)
      9 plt.show()

TypeError: cannot unpack non-iterable PathCollection object
Run Code Online (Sandbox Code Playgroud)

小智 5

将第 4 行更改为:

scatter = ax.scatter(x_arr,y_arr)
Run Code Online (Sandbox Code Playgroud)

它会解决你的问题。

scatter 只是返回一个对象。