Skip to content

Commit 330cbe1

Browse files
committed
Merge pull request #123 from mwaskom/flexible_contour_overlay
Add some flexibiltiy to contour overlays
2 parents 8823211 + cae4ebf commit 330cbe1

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Version 0.6
2424
a specific colormap and anchor points for that colormap. Additionally,
2525
the default anchor points now use robust statistics to give better
2626
values.
27+
- Contour overlay plotting was made more flexible by adding keyword arguments
28+
to control whether a colorbar should be shown and whether existing contour
29+
overlays should be removed before plotting.
2730

2831
Version 0.5
2932
-----------

surfer/viz.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,7 +1317,7 @@ def add_foci(self, coords, coords_as_verts=False, map_surface=None,
13171317

13181318
def add_contour_overlay(self, source, min=None, max=None,
13191319
n_contours=7, line_width=1.5, colormap="YlOrRd_r",
1320-
hemi=None):
1320+
hemi=None, remove_existing=True, colorbar=True):
13211321
"""Add a topographic contour overlay of the positive data.
13221322
13231323
Note: This visualization will look best when using the "low_contrast"
@@ -1343,6 +1343,11 @@ def add_contour_overlay(self, source, min=None, max=None,
13431343
If None, it is assumed to belong to the hemipshere being
13441344
shown. If two hemispheres are being shown, an error will
13451345
be thrown.
1346+
remove_existing : bool
1347+
If there is an existing contour overlay, remove it before plotting.
1348+
colorbar : bool
1349+
If True, show the colorbar for the scalar value.
1350+
13461351
"""
13471352
hemi = self._check_hemi(hemi)
13481353

@@ -1354,10 +1359,11 @@ def add_contour_overlay(self, source, min=None, max=None,
13541359
scalar_data = _prepare_data(scalar_data)
13551360

13561361
# Maybe get rid of an old overlay
1357-
if hasattr(self, "contour"):
1362+
if hasattr(self, "contour") and remove_existing:
13581363
for c in self.contour_list:
13591364
c['surface'].remove()
1360-
c['colorbar'].visible = False
1365+
if c['colorbar'] is not None:
1366+
c['colorbar'].visible = False
13611367

13621368
# Process colormap argument into a lut
13631369
lut = create_color_lut(colormap)
@@ -1369,7 +1375,8 @@ def add_contour_overlay(self, source, min=None, max=None,
13691375
cl.append(brain['brain'].add_contour_overlay(scalar_data,
13701376
min, max,
13711377
n_contours,
1372-
line_width, lut))
1378+
line_width, lut,
1379+
colorbar))
13731380
self.contour_list = cl
13741381
self._toggle_render(True, views)
13751382

@@ -2523,7 +2530,8 @@ def add_foci(self, foci_coords, scale_factor, color, alpha, name):
25232530
return points
25242531

25252532
def add_contour_overlay(self, scalar_data, min=None, max=None,
2526-
n_contours=7, line_width=1.5, lut=None):
2533+
n_contours=7, line_width=1.5, lut=None,
2534+
colorbar=True):
25272535
"""Add a topographic contour overlay of the positive data"""
25282536
# Set up the pipeline
25292537
mesh = mlab.pipeline.triangular_mesh_source(self._geo.x, self._geo.y,
@@ -2546,6 +2554,8 @@ def add_contour_overlay(self, scalar_data, min=None, max=None,
25462554
bar.data_range = min, max
25472555
self._format_cbar_text(bar)
25482556
bar.scalar_bar_representation.position2 = .8, 0.09
2557+
if not colorbar:
2558+
bar.visible = False
25492559

25502560
# Set up a dict attribute with pointers at important things
25512561
return dict(surface=surf, colorbar=bar)

0 commit comments

Comments
 (0)