-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnote.py
51 lines (40 loc) · 1.13 KB
/
note.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
41
42
43
44
45
46
47
48
49
50
51
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
Grid = np.zeros((10,10))
x = 0
y = 0
Grid[y,x] = 2
Grid[5,5] = -1
cmap = mpl.colors.ListedColormap(['green','white','red'])
def updateGrid(grid):
grid = np.zeros((10,10))
grid[5,5] = -1
grid[0,0] = 2
return grid
def _forward(x):
return x
def _inverse(x):
return x
def plot_grid(grid):
norm = mpl.colors.FuncNorm((_forward, _inverse), vmin=-1, vmax=2)
ax = plt.gca()
# ax.invert_yaxis()
ax.set_xticks(np.arange(0, 10, 1))
# ax.set_yticks(np.arange(0, 10, 1))
# ax.set_xticklabels(np.arange(0, 10, 1))
# ax.set_yticklabels(np.arange(0, 10, 1))
# ax.set_xticks(np.arange(-.5, 10, 1), minor=True)
# ax.set_yticks(np.arange(-.5, 10, 1), minor=True)
ax.imshow(grid,cmap=cmap,norm=norm,origin='lower')
# Gridlines based on minor ticks
ax.grid(which='minor', color='k', linestyle='-', linewidth=2)
return ax
plt.ion()
fig = plot_grid(Grid)
plt.pause(1)
while True:
fig.remove()
Grid = updateGrid(Grid)
fig = plot_grid(Grid)
plt.pause(0.5)