TypeError: Axes3D


Question

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

1
4
5/28/2013 11:34:13 AM

Accepted Answer

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))
9
5/28/2013 11:43:53 AM

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 ;)


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon