Reputation: 13062
I have a list with a pair of tuples to represent the x and y coordinates of location for a GPS log. This is simply like [(x1, y1), (x2,y2), (x3, y3)....].
There can be several repetition of the same (x,y) location in the list. Now, what I want to do is to draw a figure representing these locations and also show the relative frequency, i.e places visited most often. I would guess either a bubble chart with the size of bubble representing the number of times the place is visited or a heatmap would be the most useful way.
What would be the simplest way to do this in python using the matplotlib library?
Upvotes: 2
Views: 7066
Reputation: 879621
Use a collections.Counter to count the frequency of (x,y)
pairs.
Use plt.scatter's s
parameter to control the sizes, and the c
parameter to control the colors. Both the s
and c
parameters can take a sequence as their argument.
import matplotlib.pyplot as plt
import collections
import numpy as np
data = [tuple(pair)
for pair in np.random.uniform(5, size=(20,2))
for c in range(np.random.random_integers(50))]
count = collections.Counter(data)
points = count.keys()
x, y = zip(*points)
sizes = np.array(count.values())**2
plt.scatter(x, y, s=sizes, marker='o', c=sizes)
plt.show()
Upvotes: 4