当前位置: 首页>>代码示例>>Python>>正文


Python img_plotting.plot_stat_map函数代码示例

本文整理汇总了Python中nilearn.plotting.img_plotting.plot_stat_map函数的典型用法代码示例。如果您正苦于以下问题:Python plot_stat_map函数的具体用法?Python plot_stat_map怎么用?Python plot_stat_map使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了plot_stat_map函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot

    def plot(self, limit=5, anatomical=None):
        """ Create a quick plot of self.data.  Will plot each image separately

        Args:
            limit: max number of images to return
            anatomical: nifti image or file name to overlay

        """

        if anatomical is not None:
            if not isinstance(anatomical, nib.Nifti1Image):
                if type(anatomical) is str:
                    anatomical = nib.load(anatomical)
                else:
                    raise ValueError("anatomical is not a nibabel instance")
        else:
            anatomical = get_anatomical()

    
        if self.data.ndim == 1:
            plot_stat_map(self.to_nifti(), anatomical, cut_coords=range(-40, 50, 10), display_mode='z', 
                black_bg=True, colorbar=True, draw_cross=False)
        else:
            for i in xrange(self.data.shape[0]):
                if i < limit:
                    # plot_roi(self.nifti_masker.inverse_transform(self.data[i,:]), self.anatomical)
                    # plot_stat_map(self.nifti_masker.inverse_transform(self.data[i,:]), 
                    plot_stat_map(self[i].to_nifti(), anatomical, cut_coords=range(-40, 50, 10), display_mode='z', 
                        black_bg=True, colorbar=True, draw_cross=False)
开发者ID:burnash,项目名称:neurolearn,代码行数:29,代码来源:data.py

示例2: test_singleton_ax_dim

def test_singleton_ax_dim():
    for axis, direction in enumerate("xyz"):
        shape = [5, 6, 7]
        shape[axis] = 1
        img = nibabel.Nifti1Image(np.ones(shape), np.eye(4))
        plot_stat_map(img, None, display_mode=direction)
        plt.close()
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:7,代码来源:test_img_plotting.py

示例3: test_plotting_functions_with_cmaps

def test_plotting_functions_with_cmaps():
    img = load_mni152_template()
    cmaps = ['Paired', 'Set1', 'Set2', 'Set3']
    for cmap in cmaps:
        plot_roi(img, cmap=cmap, colorbar=True)
        plot_stat_map(img, cmap=cmap, colorbar=True)
        plot_glass_brain(img, cmap=cmap, colorbar=True)

    if LooseVersion(matplotlib.__version__) >= LooseVersion('2.0.0'):
        plot_stat_map(img, cmap='viridis', colorbar=True)

    plt.close()
开发者ID:jeromedockes,项目名称:nilearn,代码行数:12,代码来源:test_img_plotting.py

示例4: test_plot_functions

def test_plot_functions():
    img = _generate_img()

    # smoke-test for each plotting function with default arguments
    for plot_func in [plot_anat, plot_img, plot_stat_map, plot_epi, plot_glass_brain]:
        with tempfile.NamedTemporaryFile(suffix=".png") as fp:
            plot_func(img, output_file=fp.name)

    # test for bad input arguments (cf. #510)
    ax = plt.subplot(111, rasterized=True)
    with tempfile.NamedTemporaryFile(suffix=".png") as fp:
        plot_stat_map(img, symmetric_cbar=True, output_file=fp.name, axes=ax, vmax=np.nan)
    plt.close()
开发者ID:agramfort,项目名称:nilearn,代码行数:13,代码来源:test_img_plotting.py

示例5: test_plot_stat_map_with_nans

def test_plot_stat_map_with_nans():
    img = _generate_img()
    data = img.get_data()

    data[6, 5, 1] = np.nan
    data[1, 5, 2] = np.nan
    data[1, 3, 2] = np.nan
    data[6, 5, 2] = np.inf

    img = nibabel.Nifti1Image(data, mni_affine)
    plot_epi(img)
    plot_stat_map(img)
    plot_glass_brain(img)
开发者ID:jeromedockes,项目名称:nilearn,代码行数:13,代码来源:test_img_plotting.py

示例6: test_save_plot

def test_save_plot():
    img = _generate_img()

    kwargs_list = [{}, {'display_mode': 'x', 'cut_coords': 3}]

    for kwargs in kwargs_list:
        with tempfile.NamedTemporaryFile(suffix='.png') as fp:
            display = plot_stat_map(img, output_file=fp.name, **kwargs)
            assert_true(display is None)

        display = plot_stat_map(img, **kwargs)
        with tempfile.NamedTemporaryFile(suffix='.png') as fp:
            display.savefig(fp.name)
开发者ID:amadeuskanaan,项目名称:nilearn,代码行数:13,代码来源:test_img_plotting.py

示例7: test_save_plot

def test_save_plot():
    mp.use('template', warn=False)
    import matplotlib.pyplot as plt
    plt.switch_backend('template')
    img = _generate_img()

    kwargs_list = [{}, {'display_mode': 'x', 'cut_coords': 3}]

    for kwargs in kwargs_list:
        with tempfile.TemporaryFile(suffix='.png') as fp:
            display = plot_stat_map(img, output_file=fp.name, **kwargs)
            assert_true(display is None)

        display = plot_stat_map(img, **kwargs)
        with tempfile.TemporaryFile(suffix='.png') as fp:
            display.savefig(fp.name)
开发者ID:fabianp,项目名称:nilearn,代码行数:16,代码来源:test_img_plotting.py

示例8: test_save_plot

def test_save_plot():
    img = _generate_img()

    kwargs_list = [{}, {'display_mode': 'x', 'cut_coords': 3}]

    for kwargs in kwargs_list:
        filename = tempfile.mktemp(suffix='.png')
        try:
            display = plot_stat_map(img, output_file=filename, **kwargs)
        finally:
            os.remove(filename)
        assert_true(display is None)

        display = plot_stat_map(img, **kwargs)
        filename = tempfile.mktemp(suffix='.png')
        try:
            display.savefig(filename)
        finally:
            os.remove(filename)
开发者ID:GaelVaroquaux,项目名称:nilearn,代码行数:19,代码来源:test_img_plotting.py

示例9: test_plotting_functions_with_nans_in_bg_img

def test_plotting_functions_with_nans_in_bg_img():
    bg_img = _generate_img()
    bg_data = bg_img.get_data()

    bg_data[6, 5, 1] = np.nan
    bg_data[1, 5, 2] = np.nan
    bg_data[1, 3, 2] = np.nan
    bg_data[6, 5, 2] = np.inf

    bg_img = nibabel.Nifti1Image(bg_data, mni_affine)
    plot_anat(bg_img)
    # test with plot_roi passing background image which contains nans values
    # in it
    roi_img = _generate_img()
    plot_roi(roi_img=roi_img, bg_img=bg_img)
    stat_map_img = _generate_img()
    plot_stat_map(stat_map_img=stat_map_img, bg_img=bg_img)

    plt.close()
开发者ID:jeromedockes,项目名称:nilearn,代码行数:19,代码来源:test_img_plotting.py

示例10: test_plot_functions

def test_plot_functions():
    mp.use('template', warn=False)
    import matplotlib.pyplot as plt
    plt.switch_backend('template')
    img = _generate_img()

    # smoke-test for each plotting function with default arguments
    for plot_func in [plot_anat, plot_img, plot_stat_map, plot_epi,
                      plot_glass_brain]:
        with tempfile.TemporaryFile(suffix='.png') as fp:
            plot_func(img, output_file=fp.name)

    # test for bad input arguments (cf. #510)
    ax = plt.subplot(111, rasterized=True)
    with tempfile.TemporaryFile(suffix='.png') as fp:
        plot_stat_map(
            img, symmetric_cbar=True,
            output_file=fp.name,
            axes=ax, vmax=np.nan)
    plt.close()
开发者ID:fabianp,项目名称:nilearn,代码行数:20,代码来源:test_img_plotting.py

示例11: test_plot_functions

def test_plot_functions():
    img = _generate_img()

    # smoke-test for each plotting function with default arguments
    for plot_func in [plot_anat, plot_img, plot_stat_map, plot_epi,
                      plot_glass_brain]:
        filename = tempfile.mktemp(suffix='.png')
        try:
            plot_func(img, output_file=filename)
        finally:
            os.remove(filename)

    # test for bad input arguments (cf. #510)
    ax = plt.subplot(111, rasterized=True)
    filename = tempfile.mktemp(suffix='.png')
    try:
        plot_stat_map(img, symmetric_cbar=True,
                      output_file=filename,
                      axes=ax, vmax=np.nan)
    finally:
        os.remove(filename)
    plt.close()
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:22,代码来源:test_img_plotting.py

示例12: test_plot_stat_map_threshold_for_affine_with_rotation

def test_plot_stat_map_threshold_for_affine_with_rotation():
    # threshold was not being applied when affine has a rotation
    # see https://github.com/nilearn/nilearn/issues/599 for more details
    data = np.random.randn(10, 10, 10)
    # matrix with rotation
    affine = np.array([[-3.0, 1.0, 0.0, 1.0], [-1.0, -3.0, 0.0, -2.0], [0.0, 0.0, 3.0, 3.0], [0.0, 0.0, 0.0, 1.0]])
    img = nibabel.Nifti1Image(data, affine)
    display = plot_stat_map(img, bg_img=None, threshold=1e6, display_mode="z", cut_coords=1)
    # Next two lines retrieve the numpy array from the plot
    ax = list(display.axes.values())[0].ax
    plotted_array = ax.images[0].get_array()
    # Given the high threshold the array should be entirely masked
    assert_true(plotted_array.mask.all())
开发者ID:KentChun33333,项目名称:nilearn,代码行数:13,代码来源:test_img_plotting.py

示例13: test_plot_stat_map_threshold_for_uint8

def test_plot_stat_map_threshold_for_uint8():
    # mask was applied in [-threshold, threshold] which is problematic
    # for uint8 data. See https://github.com/nilearn/nilearn/issues/611
    # for more details
    data = 10 * np.ones((10, 10, 10), dtype='uint8')
    affine = np.eye(4)
    img = nibabel.Nifti1Image(data, affine)
    threshold = np.array(5, dtype='uint8')
    display = plot_stat_map(img, bg_img=None, threshold=threshold,
                            display_mode='z', cut_coords=1)
    # Next two lines retrieve the numpy array from the plot
    ax = list(display.axes.values())[0].ax
    plotted_array = ax.images[0].get_array()
    # Make sure that no data is masked
    assert_equal(plotted_array.mask.sum(), 0)
开发者ID:carlosf,项目名称:nilearn,代码行数:15,代码来源:test_img_plotting.py

示例14: test_plot_stat_map_threshold_for_uint8

def test_plot_stat_map_threshold_for_uint8():
    # mask was applied in [-threshold, threshold] which is problematic
    # for uint8 data. See https://github.com/nilearn/nilearn/issues/611
    # for more details
    data = 10 * np.ones((10, 10, 10), dtype="uint8")
    # Having a zero minimum value is important to reproduce
    # https://github.com/nilearn/nilearn/issues/762
    data[0, 0, 0] = 0
    affine = np.eye(4)
    img = nibabel.Nifti1Image(data, affine)
    threshold = np.array(5, dtype="uint8")
    display = plot_stat_map(img, bg_img=None, threshold=threshold, display_mode="z", cut_coords=[0])
    # Next two lines retrieve the numpy array from the plot
    ax = list(display.axes.values())[0].ax
    plotted_array = ax.images[0].get_array()
    # Make sure that there is one value masked
    assert_equal(plotted_array.mask.sum(), 1)
    # Make sure that the value masked is in the corner. Note that the
    # axis orientation seem to be flipped, hence (0, 0) -> (-1, 0)
    assert_true(plotted_array.mask[-1, 0])
开发者ID:KentChun33333,项目名称:nilearn,代码行数:20,代码来源:test_img_plotting.py

示例15: test_outlier_cut_coords

def test_outlier_cut_coords():
    """ Test to plot a subset of a large set of cuts found for a small area."""
    bg_img = load_mni152_template()

    data = np.zeros((79, 95, 79))
    affine = np.array([[  -2.,    0.,    0.,   78.],
                       [   0.,    2.,    0., -112.],
                       [   0.,    0.,    2.,  -70.],
                       [   0.,    0.,    0.,    1.]])

    # Color a cube around a corner area:
    x, y, z = 20, 22, 60
    x_map, y_map, z_map = coord_transform(x, y, z,
                                          np.linalg.inv(affine))

    data[int(x_map) - 1:int(x_map) + 1,
         int(y_map) - 1:int(y_map) + 1,
         int(z_map) - 1:int(z_map) + 1] = 1
    img = nibabel.Nifti1Image(data, affine)
    cuts = find_cut_slices(img, n_cuts=20, direction='z')

    p = plot_stat_map(img, display_mode='z', cut_coords=cuts[-4:],
                      bg_img=bg_img)
开发者ID:AlexandreAbraham,项目名称:nilearn,代码行数:23,代码来源:test_img_plotting.py


注:本文中的nilearn.plotting.img_plotting.plot_stat_map函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。