Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pyplot.scatter()方法绘制元组列表(x坐标、y坐标、颜色)_Python_Matplotlib_Plot - Fatal编程技术网

Python 使用pyplot.scatter()方法绘制元组列表(x坐标、y坐标、颜色)

Python 使用pyplot.scatter()方法绘制元组列表(x坐标、y坐标、颜色),python,matplotlib,plot,Python,Matplotlib,Plot,首先,我创建一个元组列表(要绘制的点)。每个元组由3个数字组成(点的x坐标、y坐标、c颜色) 现在我想用pyplot.scatter()方法绘制它 如果我这样指定绘图: plt.scatter(*zip(*data_points)) plt.show() 然后将前两个列表读取为x和y坐标(这是正确的),但将第三个列表读取为点的大小(这在文档中是正确的)。 如何告诉python将我的第三个列表作为pyplot.scatter()方法的颜色属性(该方法的第四个参数) 附言 matplotlib.p

首先,我创建一个元组列表(要绘制的点)。每个元组由3个数字组成(点的x坐标、y坐标、c颜色)

现在我想用pyplot.scatter()方法绘制它

如果我这样指定绘图:

plt.scatter(*zip(*data_points))
plt.show()
然后将前两个列表读取为x和y坐标(这是正确的),但将第三个列表读取为点的大小(这在文档中是正确的)。 如何告诉python将我的第三个列表作为pyplot.scatter()方法的颜色属性(该方法的第四个参数)

附言

matplotlib.pyplot.scatter(x,y,s=20,c=u'b',marker=u'o',cmap=None, norm=None,vmin=None,vmax=None,alpha=None,线宽=None, 垂直=无,保持=无,**kwargs)


如果您可以更改
数据\u点
,并且对额外的开销没有问题,您只需添加一个额外的数字来指定大小:

data_points = [(random.randint(low,high), random.randint(low,high),
                15, random.randint(low,high))for x in range(count)]
plt.scatter(*zip(*data_points))
plt.show()

您可以更改数据点吗?这是一个选项。谢谢:)我对所有这些数据结构都不熟悉,不确定我是否以最理想的方式做了这些事情。欢迎:-)(顺便说一句,这不是最佳的,但很简洁)
data_points = [(random.randint(low,high), random.randint(low,high),
                15, random.randint(low,high))for x in range(count)]
plt.scatter(*zip(*data_points))
plt.show()