Debian Codegraph @

img/facilityLocationGIF.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 import matplotlib
2 matplotlib.use('Agg')
3
4 import matplotlib.pyplot as plt
5 from matplotlib.animation import FuncAnimation
6
7 import numpy
8 numpy.random.seed(0)
9
10 import seaborn; seaborn.set_style('whitegrid')
11 from apricot import FacilityLocationSelection
12
13 numpy.random.seed(0)
14 X = numpy.concatenate([numpy.random.normal((1, 1), 0.5, size=(15, 2)),
15 numpy.random.normal((6, 3), 0.5, size=(25, 2)),
16 numpy.random.normal((5, 7), 0.5, size=(40, 2)),
17 numpy.random.normal((1, 7), 0.5, size=(30, 2)),
18 numpy.random.normal((10, 4), 0.5, size=(15, 2)),
19 numpy.random.normal((3, 4), 0.5, size=(15, 2))])
20
21 Xi = FacilityLocationSelection(6, 'euclidean').fit_transform(X)
22 Xr = numpy.random.choice(numpy.arange(X.shape[0]), size=6)
23 Xr = X[Xr]
24
25 fig = plt.figure(figsize=(8, 6))
26 ax = plt.subplot(111)
27 ax.scatter(X[:,0], X[:,1], s=10)
28 ax.legend(fontsize=14)
29 ax.set_xlim(-1, 14)
30 #ax.set_ylim(0, 7)
31 ax.axis('off')
32 plt.grid(False)
33 seaborn.despine(ax=ax)
34 fig.set_tight_layout(True)
35
36 def update(i):
37 ax.clear()
38 ax.scatter(X[:,0], X[:,1], s=10)
39 ax.scatter(Xi[:i,0], Xi[:i,1], color="#FF6600", label="Submodular Selection")
40 ax.scatter(Xr[:i,0], Xr[:i,1], color="#8A2BE2", label="Random Selection", alpha=0.6)
41 ax.legend(fontsize=14)
42 ax.set_xlim(-1, 14)
43 ax.axis('off')
44 plt.grid(False)
45 return ax
46
47 anim = FuncAnimation(fig, update, frames=range(7), interval=1000)
48 anim.save('fl.gif', dpi=80, writer='imagemagick')