-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_spins.py
More file actions
61 lines (43 loc) · 1.26 KB
/
plot_spins.py
File metadata and controls
61 lines (43 loc) · 1.26 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
55
56
import numpy as np
import matplotlib.pyplot as plt
import math
fig, ax = plt.subplots()
data = []
f = open("data/raw_positions.txt")
i = 1
MAXORDERFIGS = 5#maximum number of orders of magnitude of images
def hinton(matrix, i, max_weight=None, ax=None):
"""Draw Hinton diagram for visualizing a weight matrix."""
plt.clf()
ax = ax if ax is not None else plt.gca()
if not max_weight:
max_weight = 2**np.ceil(np.log(np.abs(matrix).max())/np.log(2))
ax.patch.set_facecolor('gray')
ax.set_aspect('equal', 'box')
ax.xaxis.set_major_locator(plt.NullLocator())
ax.yaxis.set_major_locator(plt.NullLocator())
for y in range(0,len(data)):
for x in range(0,len(data[0])):
color = 'black'
if data[y][x] > 0.1:
color = 'white'
size = 1
rect = plt.Rectangle([x - size / 2, y - size / 2], size, size,
facecolor=color, edgecolor=color)
ax.add_patch(rect)
ax.autoscale_view()
numdigits = int(math.ceil(math.log10(i+1)))
plt.savefig('images/SpinData'+('0'*(MAXORDERFIGS-numdigits))+str(i)+'.png', bbox_inches='tight')
for line in f:
if line == "TEMP CHANGED\n":
break
if line != "TIME!\n":
data_aux = []
for z in line.split():
data_aux.append(int(z))
data.append(data_aux)
else:
hinton(data,i)
i+=1
data = []
f.close()