9

I'm trying to plot a 3D scatter with matplotlib The problem is that I can't change the marker's size I have this

scat = plt.scatter([boid_.pos[0] for boid_ in flock],
                   [boid_.pos[1] for boid_ in flock],
                   [boid_.pos[2] for boid_ in flock], 
                   marker='o', s=5)

But I get the error

TypeError: scatter() got multiple values for keyword argument 's'

Without that, the plot works fine. Where is the problem? Or is there another way to change the size?

1 Answer 1

23

This function takes in two args before the keyword args:

scatter(x, y, s=20, ...)

And you are passing in three, so you are specifying s twice (once implicitly and once explicitly).

Actually, I think you are trying to use the 2D scatter plot function instead of a 3D one. You probably want to do this instead:

from mpl_toolkits.mplot3d import Axes3D
Axes3D.scatter( ... )
Sign up to request clarification or add additional context in comments.

2 Comments

Maybe I should have written it in my post, but I had fig=plt.figure() and ax = Axes3D(fig) before. I still got an error if I use Axes3D.scatter: TypeError: unbound method scatter() must be called with Axes3D instance as first argument (got list instance instead)
I'm sorry, I figured it out, that doing ax = fig.add_subplot(111, projection = '3d') and then ax.scatter() , I don't get an erro anymore. Your answer made me realize that maybe I had something wrong with the scatter. Thanks for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.