从元组中的点集绘制散点图 [英] Make scatter plot from set of points in tuples
本文介绍了从元组中的点集绘制散点图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在元组中有一组点,如下所示:
I have set of points in tuples, like this:
>>> s
set([(209, 147),
(220, 177),
(222, 181),
(225, 185),
(288, 173),
(211, 155),
(222, 182)])
做这个集合的散点图的正确方法是什么?
What is the right way to do scatter plot of this set?
推荐答案
您可以这样做:
x,y = zip(*s)
plt.scatter(x, y)
甚至在单行"中:
plt.scatter(*zip(*s))
zip()
可用于打包和解包数组,以及在您使用进行调用时 method(* list_or_tuple)
,列表或元组中的每个元素都作为参数传递.
zip()
can be used to pack and unpack arrays and when you call using method(*list_or_tuple)
, each element in the list or tuple is passed as an argument.
这篇关于从元组中的点集绘制散点图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文