Skip to content

Commit f966be1

Browse files
author
lsampras
committed
refactor visualization functions
1 parent af2fab8 commit f966be1

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

Visualization/MapVisualizer.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

mapworks/visualization.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import matplotlib.pyplot as plt
44
import matplotlib.cm as cm
5+
import matplotlib.colors as colors
56
import numpy as np
67
import itertools
78

@@ -204,3 +205,18 @@ def mouse_move(event):
204205
x, y = int(round(event.xdata)), int(round(event.ydata))
205206
print(x, y)
206207
return
208+
209+
def saveColorGradedMap(name,map,color='Reds',maxRange=1.0,minRange=0.0,underRange=(0.,0.,0.),overRange=(1.,1.,1.)):
210+
norm = colors.Normalize(vmin=minRange, vmax=maxRange)
211+
cmap = cm.get_cmap(color)
212+
cmap.set_under(underRange)
213+
cmap.set_over(overRange)
214+
215+
fig, ax = plt.subplots()
216+
ax.imshow(map, cmap=cmap, norm=norm)
217+
# draw gridlines
218+
ax.grid(which='major', axis='both', linestyle='-', color='k', linewidth=2)
219+
ax.set_xticks(np.arange(-0.5, map.shape[0], 1))
220+
ax.set_yticks(np.arange(-0.5, map.shape[1], 1))
221+
plt.savefig(name + ".png")
222+
plt.close(fig)

pheromone-driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
import moves
44
import random
5-
from Visualization.MapVisualizer import saveColorGradedMap
5+
from mapworks import visualization
66

77
np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(x)})
88

@@ -27,7 +27,7 @@ def addEnemy():
2727
if(turn%1 == 0):
2828
addEnemy()
2929
# TODO: make sure directory exists
30-
saveColorGradedMap("pheromone-sample/{}".format(turn),ph.map,underRange=(0.,0.,1.))
30+
visualization.saveColorGradedMap("pheromone-sample/{}".format(turn),ph.map,underRange=(0.,0.,1.))
3131
ph.propogate()
3232

3333

0 commit comments

Comments
 (0)