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?

PerroNoob
  • 843
  • 2
  • 16
  • 36

1 Answers1

21

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( ... )
wim
  • 338,267
  • 99
  • 616
  • 750
  • 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)` – PerroNoob Oct 18 '13 at 16:11
  • 1
    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 – PerroNoob Oct 18 '13 at 16:41