Skip to content

Commit 519ffc7

Browse files
authored
Merge pull request #78 from rmarkello/ref/plotting
[REF] Pass through kwargs to plot_fsaverage
2 parents 9f7cddf + a7444e7 commit 519ffc7

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

netneurotools/plotting.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,9 @@ def plot_conte69(data, lhlabel, rhlabel, surf='midthickness',
302302
def plot_fsaverage(data, *, lhannot, rhannot, order='LR', surf='pial',
303303
views='lat', vmin=None, vmax=None, center=None, mask=None,
304304
colormap='viridis', colorbar=True, alpha=0.8,
305-
label_fmt='%.2f', num_labels=3,
306-
size_per_view=500, subjects_dir=None, subject='fsaverage',
307-
noplot=None):
305+
label_fmt='%.2f', num_labels=3, size_per_view=500,
306+
subject_id='fsaverage', subjects_dir=None,
307+
noplot=None, **kwargs):
308308
"""
309309
Plots `data` to fsaverage brain using `annot` as parcellation
310310
@@ -358,8 +358,8 @@ def plot_fsaverage(data, *, lhannot, rhannot, order='LR', surf='pial',
358358
'fsaverage'
359359
noplot : list, optional
360360
List of names in `lhannot` and `rhannot` to not plot. It is assumed
361-
these are NOT present in `data`. If not specified, by default 'unknown'
362-
and 'corpuscallosum' will not be plotted if they are present in the
361+
these are NOT present in `data`. By default 'unknown' and
362+
'corpuscallosum' will never be plotted if they are present in the
363363
provided annotation files. Default: None
364364
365365
Returns
@@ -373,22 +373,22 @@ def plot_fsaverage(data, *, lhannot, rhannot, order='LR', surf='pial',
373373
try:
374374
from surfer import Brain
375375
except ImportError:
376-
raise ImportError('Cannot use plot_to_fsaverage() if pysurfer is not '
376+
raise ImportError('Cannot use plot_fsaverage() if pysurfer is not '
377377
'installed. Please install pysurfer and try again.')
378378

379379
# check for FreeSurfer install w/fsaverage; otherwise, fetch required
380380
try:
381-
subject_id, subjects_dir = check_fs_subjid(subject, subjects_dir)
381+
subject_id, subjects_dir = check_fs_subjid(subject_id, subjects_dir)
382382
except FileNotFoundError:
383-
if subject != 'fsaverage':
383+
if subject_id != 'fsaverage':
384384
raise ValueError('Provided subject {} does not exist in provided '
385385
'subjects_dir {}'
386-
.format(subject, subjects_dir))
386+
.format(subject_id, subjects_dir))
387387
from .datasets import fetch_fsaverage
388388
from .datasets.utils import _get_data_dir
389389
fetch_fsaverage()
390390
subjects_dir = os.path.join(_get_data_dir(), 'tpl-fsaverage')
391-
subject_id, subjects_dir = check_fs_subjid(subject, subjects_dir)
391+
subject_id, subjects_dir = check_fs_subjid(subject_id, subjects_dir)
392392

393393
# cast data to float (required for NaNs)
394394
data = np.asarray(data, dtype='float')
@@ -417,14 +417,16 @@ def plot_fsaverage(data, *, lhannot, rhannot, order='LR', surf='pial',
417417

418418
# size of window will depend on # of views provided
419419
size = (size_per_view * 2, size_per_view * len(views))
420-
brain = Brain(subject_id=subject, hemi='split', surf=surf,
421-
subjects_dir=subjects_dir, background='white',
422-
views=views, size=size)
420+
brain_kws = dict(background='white')
421+
brain_kws.update(**kwargs)
422+
brain = Brain(subject_id=subject_id, hemi='split', surf=surf,
423+
subjects_dir=subjects_dir, views=views, size=size,
424+
**brain_kws)
423425

424426
for annot, hemi in zip([lhannot, rhannot], ['lh', 'rh']):
425427
# loads annotation data for hemisphere, including vertex `labels`!
426428
if not annot.startswith(os.path.abspath(os.sep)):
427-
annot = os.path.join(subjects_dir, subject, 'label', annot)
429+
annot = os.path.join(subjects_dir, subject_id, 'label', annot)
428430
labels, ctab, names = nib.freesurfer.read_annot(annot)
429431

430432
# get appropriate data, accounting for hemispheric asymmetry
@@ -449,7 +451,6 @@ def plot_fsaverage(data, *, lhannot, rhannot, order='LR', surf='pial',
449451
inds = sorted([names.index(n) for n in currdrop])
450452
for i in inds:
451453
hemidata = np.insert(hemidata, i, np.nan)
452-
# fulldata = np.insert(hemidata, inds - np.arange(len(inds)), np.nan)
453454
vtx_data = hemidata[labels]
454455
not_nan = ~np.isnan(vtx_data)
455456

@@ -493,7 +494,7 @@ def plot_fsaverage(data, *, lhannot, rhannot, order='LR', surf='pial',
493494
return brain
494495

495496

496-
def plot_point_brain(data, coords, views=None, cbar=False, figsize=(5, 5),
497+
def plot_point_brain(data, coords, views=None, cbar=False, figsize=(4, 4.8),
497498
robust=True, size=50, **kwargs):
498499
"""
499500
Plots `data` as a cloud of points in 3D space based on specified `coords`
@@ -511,7 +512,7 @@ def plot_point_brain(data, coords, views=None, cbar=False, figsize=(5, 5),
511512
cbar : bool, optional
512513
Whether to also show colorbar. Default: False
513514
figsize : tuple, optional
514-
Figure size. Default: (5, 5)
515+
Figure size. Default: (4, 4.8)
515516
robust : bool, optional
516517
Whether to use robust calculation of `vmin` and `vmax` for color scale.
517518
size : int, optional

0 commit comments

Comments
 (0)