-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotter.py
More file actions
54 lines (50 loc) · 2.08 KB
/
Copy pathplotter.py
File metadata and controls
54 lines (50 loc) · 2.08 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
#! /usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
def plot_heatmap(connmat, ax=None, title=None, row_labels=None, col_labels=None, colorbar=False, annot=False, **kwargs):
if ax is None:
ax = plt.gca()
im = ax.imshow(connmat, **kwargs)
#ax.set_xticks(np.arange(connmat.shape[0]))
#ax.set_yticks(np.arange(connmat.shape[1]))
if title is not None:
ax.set_title(title)
if col_labels is not None:
ax.set_xticklabels(col_labels)
plt.setp(ax.get_xticklabels(), rotation=30, ha="center", rotation_mode="anchor")
if row_labels is not None:
ax.set_yticklabels(row_labels)
if colorbar:
ax.figure.colorbar(im, ax=ax)
if annot:
for i in range(connmat.shape[0]):
for j in range(connmat.shape[1]):
ax.text(j, i, int(connmat[i, j]), ha="center", va="center", color="w")
return im
def plot_hist(connmat, ax=None, title=None, **kwargs):
if ax is None:
ax = plt.gca()
im = ax.hist(connmat[np.triu_indices(connmat.shape[0],1)], **kwargs)
ax.set_xticklabels(ax.get_xticks(), rotation=30)
if title is not None:
ax.set_title(title)
return im
def plot_measure(measure, ax=None, title=None, violin=True, outlier_threshold=None, subject=None, **kwargs):
if ax is None:
ax = plt.gca()
measure = np.asarray(measure)
subject = np.asarray(subject)
if outlier_threshold is not None:
outliers = np.abs(measure) >= outlier_threshold
if len(measure[outliers]) > 0:
ax.scatter(measure[outliers], [1]*len(measure[outliers]), marker='d', c='k', s=10)
if subject is not None:
for i in range(len(measure[outliers])):
ax.annotate(subject[outliers][i], (measure[outliers][i], 1), textcoords="offset points", xytext=(0, 10), ha='center', rotation='vertical')
measure = measure[~outliers]
ax.set_title(title)
if violin:
im = ax.violinplot(measure, showmedians=True, vert=False)
else:
im = ax.boxplot(measure, whis=(0,100), vert=False)
return im