Skip to content

Commit 838bf0b

Browse files
author
Erik Bernhardsson
committed
marginally nicer plots
1 parent 35a1283 commit 838bf0b

File tree

6 files changed

+635
-13
lines changed

6 files changed

+635
-13
lines changed

analyze.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,21 @@ def get_n_results_dumb(q):
1919
m = re.search(r'([0-9,]+)', s)
2020
return int(m.groups()[0].replace(',', ''))
2121

22-
if True:
22+
if False:
2323
tag = 'prog_lang'
24-
items = ['java', 'c', 'c++', 'c#', 'python', 'visual basic', 'node', 'perl', 'php', 'ruby', 'go', 'swift', 'dart', 'objective c', 'cobol', 'fortran', 'lua', 'scala', 'lisp', 'haskell', 'rust', 'erlang', 'clojure', 'matlab', 'pascal', 'r', 'elixir', 'kotlin'] #, 'prolog', 'typescript']
24+
items = ['java', 'c', 'c++', 'c#', 'python', 'visual basic', 'node', 'perl', 'php', 'ruby', 'go', 'swift', 'objective c', 'cobol', 'fortran', 'lua', 'scala', 'lisp', 'haskell', 'rust', 'erlang', 'clojure', 'matlab', 'pascal', 'r', 'kotlin']
2525
verbs_ij = ['switch', 'switched', 'move', 'moved', 'code']
26-
elif False:
26+
elif True:
2727
tag = 'js_framework'
2828
items = ['react', 'angular', 'vue', 'backbone', 'ember', 'knockout', 'jquery']
2929
verbs_ij = ['switch', 'switched', 'move', 'moved']
30-
elif False:
30+
elif True:
3131
tag = 'database'
32-
items = ['mysql', 'postgres', 'mongodb', 'cassandra', 'dynamodb', 'mariadb']
32+
items = ['mysql', 'postgres', 'mongodb', 'cassandra', 'dynamodb', 'mariadb', 'riak', 'redis']
33+
verbs_ij = ['switch', 'switched', 'move', 'moved']
34+
elif False:
35+
tag = 'deep_learning_frameworks'
36+
items = ['tensorflow', 'theano', 'keras', 'lasagne', 'caffe', 'torch', 'pytorch', 'mxnet', 'deeplearning4j']
3337
verbs_ij = ['switch', 'switched', 'move', 'moved']
3438
else:
3539
tag = 'taxi_app'
@@ -62,7 +66,7 @@ def get_n_results_dumb(q):
6266
f.close()
6367
m[j][i] += n
6468

65-
def plot_mat(m, items, cm, fn, text=False, dir_text=None):
69+
def plot_mat(m, items, cm, fn, fmt, dir_text=None):
6670
s = 4 + len(items) * 0.3
6771
fig = pyplot.figure(figsize=(s, s))
6872
ax = fig.add_subplot(111)
@@ -83,19 +87,20 @@ def plot_mat(m, items, cm, fn, text=False, dir_text=None):
8387
ax.set_yticks(numpy.arange(0.5, len(items)+0.5), minor=True)
8488
ax.grid(which='minor')
8589

86-
if text:
87-
for i in range(len(items)):
88-
for j in range(len(items)):
89-
ax.text(i, j, str(int(m[i][j])), va='center', ha='center', size=7)
90+
for i in range(len(items)):
91+
for j in range(len(items)):
92+
text = fmt % m[i][j]
93+
if text != fmt % 0:
94+
ax.text(i, j, text, va='center', ha='center', size=7)
9095

9196
fig.tight_layout()
9297
pyplot.savefig(fn, dpi=300)
9398

9499
# Plot lexicographical
95100
ps = sorted(range(len(items)), key=lambda i: items[i])
96-
plot_mat(m[ps,:][:,ps], sorted(items), pyplot.cm.OrRd, '%s_matrix.png' % tag, text=True)
101+
plot_mat(m[ps,:][:,ps], sorted(items), pyplot.cm.OrRd, '%s_matrix.png' % tag, '%.0f')
97102

98-
m += numpy.eye(len(items)) # hack to fix zero entries
103+
# m += numpy.eye(len(items)) # hack to fix zero entries
99104
for item, pop in zip(items, m.sum(axis=0) + m.sum(axis=1)):
100105
print('%20s %6d' % (item, pop))
101106
m /= m.sum(axis=0)[numpy.newaxis,:]
@@ -111,4 +116,4 @@ def plot_mat(m, items, cm, fn, text=False, dir_text=None):
111116
print('| %5.2f%% | %20s |' % (u[p]*100, items[p]))
112117

113118
m_new = m[ps,:][:,ps]
114-
plot_mat(m_new, [items[p] for p in ps], pyplot.cm.BuGn, '%s_matrix_eig.png' % tag, dir_text='future popularity')
119+
plot_mat(m_new, [items[p] for p in ps], pyplot.cm.BuGn, '%s_matrix_eig.png' % tag, '%.2f', dir_text='future popularity')

0 commit comments

Comments
 (0)