Skip to content

Commit f9b03f9

Browse files
Merge pull request #552 from fazledyn-or/Fix_Improper_Method_Call
ENH: Replace saving mayavi figure to a temporary file with mlab.screenshot()
2 parents b3d202f + 576ce91 commit f9b03f9

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

nipy/labs/viz_tools/activation_maps.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ def plot_map(map, affine, cut_coords=None, anat=None, anat_affine=None,
173173
if do3d == 'interactive':
174174
offscreen = False
175175

176-
cmap = kwargs.get('cmap', plt.cm.cmap_d[plt.rcParams['image.cmap']])
176+
cmap = imshow_kwargs.get('cmap', plt.get_cmap(plt.rcParams['image.cmap']))
177177
# Computing vmin and vmax is costly in time, and is needed
178178
# later, so we compute them now, and store them for future
179179
# use
180-
vmin = kwargs.get('vmin', map.min())
181-
kwargs['vmin'] = vmin
182-
vmax = kwargs.get('vmax', map.max())
183-
kwargs['vmax'] = vmax
180+
vmin = imshow_kwargs.get('vmin', map.min())
181+
imshow_kwargs['vmin'] = vmin
182+
vmax = imshow_kwargs.get('vmax', map.max())
183+
imshow_kwargs['vmax'] = vmax
184184
try:
185185
from mayavi import mlab
186186
except ImportError:

nipy/labs/viz_tools/edge_detect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _fast_abs_percentile(map, percentile=80):
3030
return quantile(map, .01*percentile)
3131
map.sort()
3232
nb = map.size
33-
return map[.01*percentile*nb]
33+
return map[int(.01*percentile*nb)]
3434

3535

3636
def _orientation_kernel(t):

nipy/labs/viz_tools/maps_3d.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,18 @@ def m2screenshot(mayavi_fig=None, mpl_axes=None, autocrop=True):
117117
if mpl_axes is not None:
118118
plt.axes(mpl_axes)
119119

120-
filename = tempfile.mktemp('.png')
121-
mlab.savefig(filename, figure=mayavi_fig)
122-
image3d = plt.imread(filename)
120+
# XXX: This is a hack to force Mayavi to render.
121+
# It should not be needed if a GUI loop is running,
122+
# but just to be safe...
123+
# https://github.com/enthought/mayavi/issues/702
124+
mayavi_fig.scene._lift()
125+
126+
image3d = mlab.screenshot(figure=mayavi_fig)
123127
if autocrop:
124128
bg_color = mayavi_fig.scene.background
125129
image3d = autocrop_img(image3d, bg_color)
126130
plt.imshow(image3d)
127131
plt.axis('off')
128-
os.unlink(filename)
129132
# XXX: Should switch back to previous MPL axes: we have a side effect
130133
# here.
131134

0 commit comments

Comments
 (0)