-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrelation_plot.py
More file actions
executable file
·36 lines (30 loc) · 904 Bytes
/
Copy pathcorrelation_plot.py
File metadata and controls
executable file
·36 lines (30 loc) · 904 Bytes
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
#!/usr/bin/env python
#
# Quick script to visualize a correlation matrix
#
# How to use:
# Pipe in tabbed separated data such that:
# -each row is an instance/point/dataum
# -each column is a variable/feature
#
from numpy import corrcoef, transpose, arange
import matplotlib.pyplot as plt
import fileinput
#default plot filename
filename = "corr_matrix_plot"
data = []
# read in data
for line in fileinput.input():
row = [float(item) for item in line.strip().split("\t")]
data.append(row)
data_t = transpose(data)
features = len(data_t)
data = None # Clear information in data, just in case it is large
# plot the correlation matrix
fig = plt.figure()
R = corrcoef(data_t)
fig = plt.pcolor(R)
plt.colorbar()
plt.yticks(arange(0.5,float(features)+0.5),range(0,features))
plt.xticks(arange(0.5,float(features)+0.5),range(0,features))
plt.savefig(filename+'.svg', bbox_inches='tight')