# Usage: niwidgets examples¶

An online interactive version of this notebook can be found at: beta.mybinder.org/repo/janfreyberg/niwidgets

The main (and only, for now) class for volume images is NiftiWidget. It takes a path to a .nii file as input.

In [1]:

# import the .nii widget:
from niwidgets import NiftiWidget


## Interactively plotting an image¶

We’ll start by demonstrating the most useful aspect of the package: Being able to interactively slice an image file. To do so, we will import one of the example files that ships with niwidgets, a T1 weighted structural scan.

In [3]:

# Let's try a simple parcellation map from a standard atlas
from niwidgets import examplet1

test_widget = NiftiWidget(examplet1)
test_widget.nifti_plotter()


## Use plotting functions from nilearn¶

niwidgets also lets you turn standard plots from the nilearn package into widgets. You can use any of them, and provide your own keyword arguments to set the slider options (if no key word argument is provided defaults are used).

In particular, niwidgets should allow you to pick a colormap interactively for almost any plot type

### plot_epi¶

Plotting the same image but with the nilearn function plot_epi, we get this:

In [3]:

import nilearn.plotting as nip

test_widget.nifti_plotter(plotting_func=nip.plot_epi, display_mode=['ortho', 'x', 'y', 'z', 'yx', 'xz', 'yz'])

/Library/anaconda/envs/py36/lib/python3.6/site-packages/sklearn/cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
"This module will be removed in 0.20.", DeprecationWarning)


### plot_glass_brain¶

This is an example of a glass brain plot with a standard visual perception activation map from neurosynth (this also ships as an example with niwidgets:

In [4]:

from niwidgets import examplezmap
test = NiftiWidget(examplezmap)
test.nifti_plotter(plotting_func=nip.plot_glass_brain, threshold=(0.0, 10.0, 0.01),
display_mode=['ortho','xz'])


### plot_img¶

Another image slicer type plot from the nilearn package, this time with an example atlas (the CC400 atlas), and setting the colormap:

In [5]:

from niwidgets import exampleatlas
atlas_widget = NiftiWidget(exampleatlas)
atlas_widget.nifti_plotter(plotting_func=nip.plot_img, display_mode=['ortho', 'x', 'y', 'z'], colormap='hot')