TypeError: Axes3D
Solution 1
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))
Solution 2
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:
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. 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.
Update: ok I didn't see the update in David's answer, so now it's the same of course ;)
Coolcrab
Updated on June 04, 2022Comments
-
Coolcrab almost 2 years
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)
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.)
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
-
Coolcrab almost 11 yearsThat worked! Any tips on how to set the z axis though? I can't seem to set it too 400.
-
David Zwicker almost 11 yearsWhat do you mean by 'setting the z axis'? Do you want to adjust its limits?
-
Coolcrab almost 11 yearsOh no prob, I just wanted to ask something additional :P And yea I mean the limit, because
ax.axis([-400, 400, -400, 400])
does not accept a 3rd thingy -
David Zwicker almost 11 yearsJust use
ax.set_zlim(-400, 400)
.