class MapCanvas(FigureCanvas):
""" A map """
def __init__(self, parent=None):
""" Map contructor
@param parent: widget parent
@type parent: Qwidget
"""
self.parent = parent
# Building of a figure where map is drawn :
self.fig = Figure(figsize=(100, 100), # figure size in inches
dpi=72) # figure dots per inch
self.fig.set_facecolor("w") # set figure background in white
self.fig.subplots_adjust(left=0.01, # (=0.125) : the left side of the subplots of the figure
right=0.98, # (=0.9) : the right side of the subplots of the figure
bottom=0.1, # (=0.1) : the bottom of the subplots of the figure
top=0.9) # (=0.9) : the top of the subplots of the figure
# build of parent's widget :
FigureCanvas.__init__(self, self.fig) # call constructor of widget's parent
# put figure in a figure canvas
# allow resize of figure
FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
# create a toolbar for map (allows zoom, move, save ...)
self.tb = Toolbar(self, self)
def draw_map(self, array_color, palette_color, parent=None):
"""
@return: None
"""
self.fig.clear()
self.axes = self.fig.add_subplot(111) # draw of an orthogonal system
self.axes.axis('off') # remove axis
# draw of a map with array_color :
self.map = self.axes.pcolor(array_color, # array_color which contents GS' values for each cell
cmap = palette_color, alpha=1.0) # choice of color palette
self.scale = self.fig.colorbar(self.map) # draw of a map colorbar : scale of color
# intensity which changes with GS value
ac = app.getArrayColor(self.parent.project,
self.parent.mapnode,
"sum_b_user_myselection")
if self.parent.selection:
h = self.fig.get_figheight()
w = self.fig.get_figwidth()
(nbcell_size, xx) = array_color.shape
smallestdim = min(h,w)
cell_dimension = smallestdim/nbcell_size
cl = ac.tolist()
x =[code]
y =[code]
close =[code]
slose = 10000
for i in range(len(cl)):
for j in range(len(cl)):
if cl!= 0.0:
x.append(j + 0.5)
y.append(i + 0.5)
close.append(cl)
max_selected = max(close)
sizefactor = int(cell_dimension * cell_dimension * 1800 / max_selected)
close = map(lambda e: e*sizefactor, close)
self.map2 = self.axes.scatter(x, y, s=close, c='red', alpha=1.0)
draw()
FigureCanvas.draw(self)
[/code][/code][/code]