Skip to content

Commit c523ab2

Browse files
committed
saving contour and mask for highlighted areas
1 parent 55927b5 commit c523ab2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

wxmplot/imagepanel.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def autoset_margins(self):
231231
figpos = ax.get_subplotspec().get_position(self.canvas.figure)
232232
ax.set_position(figpos)
233233

234+
235+
234236
def add_highlight_area(self, mask, label=None, col=0):
235237
"""add a highlighted area -- outline an arbitrarily shape --
236238
as if drawn from a Lasso event.
@@ -240,17 +242,17 @@ def add_highlight_area(self, mask, label=None, col=0):
240242
patch = mask * np.ones(mask.shape) * 0.9
241243
cmap = self.conf.cmap[col]
242244
area = self.axes.contour(patch, cmap=cmap, levels=[0, 1])
243-
self.conf.highlight_areas.append(area)
245+
self.conf.highlight_areas.append((area, mask))
244246
if not hasattr(cmap, '_lut'):
245247
try:
246248
cmap._init()
247249
except:
248250
pass
249251
if hasattr(cmap, '_lut'):
250-
rgb = [int(i*240)^255 for i in cmap._lut[0][:3]]
251-
col = '#%02x%02x%02x' % (rgb[0], rgb[1], rgb[2])
252+
col = self.conf.get_highlight_color(mask, cmap)
252253
if label is not None:
253-
def fmt(*args, **kws): return label
254+
def fmt(*args, **kws):
255+
return label
254256
self.axes.clabel(area, fontsize=9, fmt=fmt,
255257
colors=col, rightside_up=True)
256258

@@ -263,7 +265,7 @@ def fmt(*args, **kws): return label
263265

264266
def clear_highlight_areas(self):
265267
"""clear all highlighted areas"""
266-
for area in self.conf.highlight_areas:
268+
for area, mask in self.conf.highlight_areas:
267269
if hasattr(area, 'collections'):
268270
for w in area.collections:
269271
w.remove()
@@ -275,7 +277,6 @@ def clear_highlight_areas(self):
275277
self.conf.highlight_areas = []
276278
self.canvas.redraw()
277279

278-
279280
def set_viewlimits(self, axes=None):
280281
""" update xy limits of a plot"""
281282
if axes is None:

0 commit comments

Comments
 (0)