TypeError: Axes3D

I have a problem with my Axes3D plotter, every time I put somethign 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 type he wants from me, since I just want to put the x, y, z coordinates of one 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 don't know what the problem is here.

+4
source share
2 answers

First you need to create an axis instance:

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

Alternatively you can 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
source

David’s answer doesn’t actually work for me, but the way I usually use it looks like this: you can create an axis object, as David mentioned, by creating a new subtitle:

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

Scatter () is a method that must be called on an object. The first argument passed to the method is always the object itself. Therefore, when calling this class, instead of the Axes3D class, the object and, therefore, the correct first argument is missing.

Update: ok I did not see the update in David's answer, so now this is the same, of course;)

+1
source

Source: https://habr.com/ru/post/1483135/


All Articles