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?
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.
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.
x = []; y=[]
for point in s:
x.append(point[0])
y.append(point[1])
plt.scatter(x,y)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With