Skip to content

Commit 4755e8b

Browse files
committed
Remove height and width kwargs in favor of a single size parameter
size can be either a single value, for a square window, or a tuple of values, to give the width and height of a rectangular window.
1 parent 7516de1 commit 4755e8b

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Version 0.6
1515
reproducible. While existing code that was written expecting a config
1616
file will still run, the visualization will fall back to default values.
1717
These should be updated directly in your plotting scripts.
18+
- Figure size is now specified only through the ``size`` keyword argument
19+
of :class:`Brain`. To make a rectangular window, pass a ``(width, height)``
20+
tuple. Passing a single value to ``size`` will still make a square window.
1821
- The ``cortex`` keyword argument can now be a mayavi colormap name or
1922
a ``(colormap, min, max, reverse)`` tuple for full control.
2023
- Morphometry plotting was made more flexible with the ability to pass

doc/documentation/custom_viz.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ Changing the display background
1414

1515
The display background can take any valid matplotlib color (i.e.,
1616
it can be a tuple of rgb values, an rgb hex string, or a named HTML
17-
color.
17+
color).
1818

1919
Changing the display size
2020
-------------------------
2121

22-
The default display window is 800px by 800px, but this is also
23-
customizable. You can set the size of a square window with the ``size``
24-
parameter or make a rectangular window with the ``width`` and ``height``
25-
parameters.
22+
The default display window is 800px by 800px, but this can be configured
23+
using the ``size`` keyword argument in the Brain constructor. ``size``
24+
should either be a single number to make a square window, or a pair of
25+
values, ``(width, height)``, to make a rectangular window.
2626

2727
Changing the curvature color scheme
2828
-----------------------------------

examples/plot_meg_inverse_solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"""
2323
create Brain object for visualization
2424
"""
25-
brain = Brain(subject_id, hemi, surface, width=800, height=400)
25+
brain = Brain(subject_id, hemi, surface, size=(800, 400))
2626

2727
"""
2828
read MNE dSPM inverse solution

examples/save_movie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717
create Brain object for visualization
1818
"""
19-
brain = Brain('fsaverage', 'split', 'inflated', width=800, height=400)
19+
brain = Brain('fsaverage', 'split', 'inflated', size=(800, 400))
2020

2121
"""
2222
read and display MNE dSPM inverse solution

surfer/tests/test_viz.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,16 @@ def test_brains():
7676
curvs = [True, False]
7777
titles = [None, 'Hello']
7878
cortices = ["low_contrast", ("Reds", 0, 1, False)]
79-
widths = [200, "w"]
80-
heights = [400, "h"]
81-
sizes = [None, 600]
79+
sizes = [500, (400, 300)]
8280
backgrounds = ["white", "blue"]
8381
foregrounds = ["black", "white"]
8482
figs = [None, mlab.figure()]
8583
subj_dirs = [None, subj_dir]
86-
for surf, hemi, curv, title, cort, w, h, s, bg, fg, fig, sd \
87-
in zip(surfs, hemis, curvs, titles, cortices,
88-
widths, heights, sizes,
84+
for surf, hemi, curv, title, cort, s, bg, fg, fig, sd \
85+
in zip(surfs, hemis, curvs, titles, cortices, sizes,
8986
backgrounds, foregrounds, figs, subj_dirs):
9087
brain = Brain(subject_id, hemi, surf, curv, title,
91-
cort, w, h, s, bg, fg, fig, sd)
88+
cort, s, bg, fg, fig, sd)
9289
brain.close()
9390
assert_raises(ValueError, Brain, subject_id, 'lh', 'inflated',
9491
subjects_dir='')

surfer/viz.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,9 @@ class Brain(object):
302302
'classic', 'bone', 'low_contrast', or 'high_contrast'), or the
303303
name of mayavi colormap, or a tuple with values (colormap, min,
304304
max, reverse) to fully specify the curvature colors.
305-
width, height : floats
306-
width and height (in pixels) of the display window
307-
size : float
308-
specify a square display window, overriding the width and height
305+
size : float or pair of floats
306+
the size of the window, in pixels. can be one number to specify
307+
a square window, or the (width, height) of a rectangular window.
309308
background, foreground : matplotlib colors
310309
color of the background and foreground of the display window
311310
figure : list of instances of mayavi.core.scene.Scene | None
@@ -331,10 +330,10 @@ class Brain(object):
331330
332331
"""
333332
def __init__(self, subject_id, hemi, surf, curv=True, title=None,
334-
cortex="classic", width=800, height=800, size=None,
335-
background="black", foreground="white", figure=None,
336-
subjects_dir=None, views=['lat'],
337-
show_toolbar=False, offscreen=False, config_opts=None):
333+
cortex="classic", size=800, background="black",
334+
foreground="white", figure=None, subjects_dir=None,
335+
views=['lat'], show_toolbar=False, offscreen=False,
336+
config_opts=None):
338337

339338
# Keep backwards compatability
340339
if config_opts is not None:
@@ -344,12 +343,14 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
344343
"constructor.")
345344
warn(msg)
346345
cortex = config_opts.get("cortex", cortex)
347-
width = config_opts.get("width", width)
348-
height = config_opts.get("height", height)
349-
size = config_opts.get("size", size)
350346
background = config_opts.get("background", background)
351347
foreground = config_opts.get("foreground", foreground)
352348

349+
size = config_opts.get("size", size)
350+
width = config_opts.get("width", size)
351+
height = config_opts.get("height", size)
352+
size = (width, height)
353+
353354
col_dict = dict(lh=1, rh=1, both=1, split=2)
354355
n_col = col_dict[hemi]
355356
if hemi not in col_dict.keys():
@@ -388,8 +389,7 @@ def __init__(self, subject_id, hemi, surf, curv=True, title=None,
388389
self.geo[h] = geo
389390

390391
# deal with making figures
391-
self._set_window_properties(width, height, size,
392-
background, foreground)
392+
self._set_window_properties(size, background, foreground)
393393
figures, _v = _make_viewer(figure, n_row, n_col, title,
394394
self._scene_size, offscreen)
395395
self._figures = figures
@@ -471,11 +471,12 @@ def _toggle_render(self, state, views=None):
471471
_force_render(self._figures, self._window_backend)
472472
return views
473473

474-
def _set_window_properties(self, width, height, size,
475-
background, foreground):
474+
def _set_window_properties(self, size, background, foreground):
476475
"""Set window properties that are used elsewhere."""
477476
# old option "size" sets both width and height
478-
if size is not None:
477+
try:
478+
width, height = size
479+
except TypeError:
479480
width, height = size, size
480481
self._scene_size = height, width
481482

0 commit comments

Comments
 (0)