comparison python/utils.py @ 115:550556378466

added functionalities to indicator maps
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sat, 23 Jul 2011 02:18:16 -0400
parents f03ec4697a09
children 2bf5b76320c0
comparison
equal deleted inserted replaced
114:680d4c82886d 115:550556378466
172 172
173 linestyles = PlottingPropertyValues(['-', '--', '-.', ':']) 173 linestyles = PlottingPropertyValues(['-', '--', '-.', ':'])
174 174
175 colors = PlottingPropertyValues('brgmyck') # 'w' 175 colors = PlottingPropertyValues('brgmyck') # 'w'
176 176
177 def plotIndicatorMap(indicatorMap, squareSize): 177 def plotIndicatorMap(indicatorMap, squareSize, masked = True, defaultValue=-1):
178 from numpy import array, arange, ones, ma 178 from numpy import array, arange, ones, ma
179 from matplotlib.pyplot import pcolor 179 from matplotlib.pyplot import pcolor
180 coords = array(indicatorMap.keys()) 180 coords = array(indicatorMap.keys())
181 minX = min(coords[:,0]) 181 minX = min(coords[:,0])
182 minY = min(coords[:,1]) 182 minY = min(coords[:,1])
183 X = arange(minX, max(coords[:,0])+1.1)*squareSize 183 X = arange(minX, max(coords[:,0])+1.1)*squareSize
184 Y = arange(minY, max(coords[:,1])+1.1)*squareSize 184 Y = arange(minY, max(coords[:,1])+1.1)*squareSize
185 C = -ones((len(Y), len(X))) 185 C = defaultValue*ones((len(Y), len(X)))
186 for k,v in indicatorMap.iteritems(): 186 for k,v in indicatorMap.iteritems():
187 C[k[1]-minY,k[0]-minX] = v 187 C[k[1]-minY,k[0]-minX] = v
188 masked = ma.masked_where(C<0,C) 188 if masked:
189 pcolor(X, Y, masked) 189 pcolor(X, Y, ma.masked_where(C==defaultValue,C))
190 else:
191 pcolor(X, Y, C)
190 192
191 ######################### 193 #########################
192 # file I/O section 194 # file I/O section
193 ######################### 195 #########################
194 196