简体   繁体   English

TypeError:Axes3D

[英]TypeError: Axes3D

I got a problem with my Axes3D plotter, every time I put somethign in I get TypeError: unbound method scatter() must be called with Axes3D instance as first argument (got list instance instead) 我的Axes3D绘图仪出了问题,每次我放入一些东西我得到TypeError: unbound method scatter() must be called with Axes3D instance as first argument (got list instance instead)

And I don't quite understand what kind of type it wants from me, as I just want to put the x,y,z coordinates of a single point in. (these can be lists or ints, both give errors.) 我不太明白它想要什么样的类型,因为我只想将单个点的x,y,z坐标放入。(这些可以是列表或整数,都会产生错误。)

Axes3D.scatter( Xc[l], Yc[l], Zc[l], c=(i/nbodies,i/nbodies,i/nbodies))

I really have no idea what the problem is here 我真的不知道这里有什么问题

You have to instantiate the axis first: 您必须首先实例化轴:

ax = Axes3D(plt.gcf())
ax.scatter( Xc[l], Yc[l], Zc[l], c=(i/nbodies,i/nbodies,i/nbodies))

Alternatively, you may use 或者,您可以使用

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter( Xc[l], Yc[l], Zc[l], c=(i/nbodies,i/nbodies,i/nbodies))

David's answer actually doesn't work for me, but the way I usually use it looks like this: you can create an axis object, as mentioned by David, by creating a new subplot: 大卫的答案实际上对我不起作用,但我通常使用它的方式如下:你可以通过创建一个新的子图创建一个轴对象,如David所述:

fig = figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(1,2,3)

scatter() is a method that has to be called on an object. scatter()是一个必须在对象上调用的方法。 When doing so, the first argument passed to the method is always the object itself. 这样做时,传递给方法的第一个参数始终是对象本身。 That's why, when calling it on the class Axes3D instead, the object and therefor the correct first argument is missing. 这就是为什么,当在类Axes3D上调用它时,该对象及其正确的第一个参数缺失。

Update: ok I didn't see the update in David's answer, so now it's the same of course ;) 更新:好的我没有在David的回答中看到更新,所以现在它也是一样的;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM