Python – TypeError: Axes3D

3derror-handlingmatplotlibpython

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

Best Solution

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))
Related Question