Skip to content

Commit 2a700c1

Browse files
committed
Add flexible colormap specification to contour plots
1 parent 57fd8a8 commit 2a700c1

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

surfer/viz.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,8 @@ def add_foci(self, coords, coords_as_verts=False, map_surface=None,
12491249
self._toggle_render(True, views)
12501250

12511251
def add_contour_overlay(self, source, min=None, max=None,
1252-
n_contours=7, line_width=1.5, hemi=None):
1252+
n_contours=7, line_width=1.5, colormap="RdBu_r",
1253+
hemi=None):
12531254
"""Add a topographic contour overlay of the positive data.
12541255
12551256
Note: This visualization will look best when using the "low_contrast"
@@ -1267,6 +1268,10 @@ def add_contour_overlay(self, source, min=None, max=None,
12671268
number of contours to use in the display
12681269
line_width : float
12691270
width of contour lines
1271+
colormap : string, list of colors, or array
1272+
name of matplotlib colormap to use, a list of matplotlib colors,
1273+
or a custom look up table (an n x 4 array coded with RBGA values
1274+
between 0 and 255).
12701275
hemi : str | None
12711276
If None, it is assumed to belong to the hemipshere being
12721277
shown. If two hemispheres are being shown, an error will
@@ -1287,14 +1292,17 @@ def add_contour_overlay(self, source, min=None, max=None,
12871292
c['surface'].remove()
12881293
c['colorbar'].visible = False
12891294

1295+
# Process colormap argument into a lut
1296+
lut = create_color_lut(colormap)
1297+
12901298
views = self._toggle_render(False)
12911299
cl = []
12921300
for brain in self._brain_list:
12931301
if brain['hemi'] == hemi:
12941302
cl.append(brain['brain'].add_contour_overlay(scalar_data,
12951303
min, max,
12961304
n_contours,
1297-
line_width))
1305+
line_width, lut))
12981306
self.contour_list = cl
12991307
self._toggle_render(True, views)
13001308

@@ -2243,7 +2251,7 @@ def add_foci(self, foci_coords, scale_factor, color, alpha, name):
22432251
return points
22442252

22452253
def add_contour_overlay(self, scalar_data, min=None, max=None,
2246-
n_contours=7, line_width=1.5):
2254+
n_contours=7, line_width=1.5, lut=None):
22472255
"""Add a topographic contour overlay of the positive data"""
22482256
# Set up the pipeline
22492257
mesh = mlab.pipeline.triangular_mesh_source(self._geo.x, self._geo.y,
@@ -2254,6 +2262,8 @@ def add_contour_overlay(self, scalar_data, min=None, max=None,
22542262
thresh = mlab.pipeline.threshold(mesh, low=min)
22552263
surf = mlab.pipeline.contour_surface(thresh, contours=n_contours,
22562264
line_width=line_width)
2265+
if lut is not None:
2266+
surf.module_manager.scalar_lut_manager.lut.table = lut
22572267

22582268
# Set the colorbar and range correctly
22592269
bar = mlab.scalarbar(surf,

0 commit comments

Comments
 (0)