-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviz.py
40 lines (33 loc) · 1.28 KB
/
viz.py
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
import matplotlib.pyplot as plt
import seaborn as sns
def plot_temporal_scores(scores, times, fname, chance_level=None, figsize=[12,4], title='Temporal decoding'):
fig, ax = plt.subplots(figsize=figsize)
ax.plot(times, scores, label='scores')
if chance_level:
ax.axhline(chance_level, color='k', linestyle='--', label='chance')
ax.set_xlabel('Time (ms)')
ax.set_ylabel('Score')
ax.legend()
ax.set_title(title)
if fname:
fig.savefig(fname)
plt.close()
def plot_generalization_scores(scores, fname, times, vmin=0, vmax=1, annot=True, title='', num_ticks=20):
'''
annot : write values in matrix cells.
'''
fig, ax = plt.subplots(1)
sns.heatmap(scores, annot=annot, cmap='YlOrRd', vmin=vmin, vmax=vmax,
xticklabels=times, yticklabels=times,
ax=ax)
plt.locator_params(nbins=num_ticks)
plt.setp(ax.get_xticklabels(), rotation=45, ha="right", rotation_mode="anchor") # to rotate ticks
plt.setp(ax.get_yticklabels(), rotation=0, ha="right", rotation_mode="anchor") # to rotate ticks
# ---- add titles
ax.set_xlabel('Testing Time (s)')
ax.set_ylabel('Training Time (s)')
ax.set_title(title)
ax.invert_yaxis()
if fname:
fig.savefig(fname)
plt.close()