-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
67 lines (49 loc) · 1.76 KB
/
Copy pathplot.py
File metadata and controls
67 lines (49 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# encoding: UTF-8
import matplotlib
matplotlib.use('Agg')
from matplotlib import pyplot as plt
import numpy as np
from utils import get_coordinates
from utils import get_df_at_time
def plot_at_time(df, time, max_allowed=60):
# Plot scatter
sub_df = get_df_at_time(df, time, max_allowed)
sub_df = sub_df.groupby('user_id').last().reset_index()
for user_id in list(set(sub_df.user_id)):
x, y, s, c = get_coordinates(user_id, sub_df)
plt.scatter(x, y, s, color=c, alpha=0.2)
def plot_to_time(df, time):
# Plot line and last scatter
# for every user
pass
def plot_user_to_time(df, time):
# Plot line and last scatter
pass
def init_plot(xmin, ymin, xmax, ymax):
fig = plt.figure()
plt.plot(xmin, ymin)
plt.plot(xmax, ymax)
return fig
def plot_clustering(X, time, labels, core_samples_mask, fig, save=False):
fig.clf()
ax = fig.add_subplot()
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
# Black removed and is used for noise instead.
unique_labels = set(labels)
colors = plt.cm.Spectral(np.linspace(0, 1, len(unique_labels)))
for k, col in zip(unique_labels, colors):
if k == -1:
# Black used for noise.
col = 'k'
class_member_mask = (labels == k)
xy = X[class_member_mask & core_samples_mask]
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=8)
xy = X[class_member_mask & ~core_samples_mask]
plt.plot(xy[:, 0], xy[:, 1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=6)
plt.title('Estimated number of clusters: %d' % n_clusters_)
if save:
plt.savefig("images/res%08d.png" % time)
else:
plt.show()