Matplotlib scatter marker size

2019-06-17 18:23发布

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条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-06-17 18:57

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( ... )
查看更多
登录 后发表回答