Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 550
user Avatar asked Jul 04 '13 22:07

user


People also ask

How do you plot a tuple?

Get the x, y and z data points from the list of tuples. Return the coordinate matrices from the coordinate vectors. Get the h data points for the surface plot. Create a new figure or activate an existing figure.


2 Answers

You can do:

x,y = zip(*s)
plt.scatter(x, y)

Or even in an "one-liner":

plt.scatter(*zip(*s))

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.

like image 96
Saullo G. P. Castro Avatar answered Sep 29 '22 01:09

Saullo G. P. Castro


x = []; y=[]
for point in s:
   x.append(point[0])
   y.append(point[1])
plt.scatter(x,y)
like image 26
Pablo Avatar answered Sep 29 '22 01:09

Pablo