Python Matplotlib 散点标记大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19451400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:46:32  来源:igfitidea点击:

Matplotlib scatter marker size

pythonmatplotlibsizescatter-plot

提问by PerroNoob

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

我正在尝试绘制 3D 散点图matplotlib问题是我无法更改标记的大小我有这个

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?

没有那个,情节运作良好。问题出在哪儿?或者有其他方法可以改变大小吗?

采纳答案by wim

This function takes in two args before the keyword args:

此函数在关键字 args 之前接受两个 args:

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

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

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

并且您传入了三个,因此您指定了s两次(一次隐式,一次显式)。

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:

实际上,我认为您正在尝试使用 2D 散点图函数而不是 3D 散点图函数。你可能想这样做:

from mpl_toolkits.mplot3d import Axes3D
Axes3D.scatter( ... )