Ejemplo n.º 1
0
def test_plot_img_comparison():
    fig, axes = plt.subplots(2, 1)
    axes = axes.ravel()
    kwargs = {"shape": (3, 2, 4), "length": 5}
    query_images, mask_img = data_gen.generate_fake_fmri(
        rand_gen=np.random.RandomState(0), **kwargs)
    # plot_img_comparison doesn't handle 4d images ATM
    query_images = list(image.iter_img(query_images))
    target_images, _ = data_gen.generate_fake_fmri(
        rand_gen=np.random.RandomState(1), **kwargs)
    target_images = list(image.iter_img(target_images))
    target_images[0] = query_images[0]
    masker = NiftiMasker(mask_img).fit()
    correlations = plotting.plot_img_comparison(
        target_images, query_images, masker, axes=axes, src_label="query")
    assert len(correlations) == len(query_images)
    assert correlations[0] == pytest.approx(1.)
    ax_0, ax_1 = axes
    # 5 scatterplots
    assert len(ax_0.collections) == 5
    assert len(ax_0.collections[0].get_edgecolors() == masker.transform(
        target_images[0]).ravel().shape[0])
    assert ax_0.get_ylabel() == "query"
    assert ax_0.get_xlabel() == "image set 1"
    # 5 regression lines
    assert len(ax_0.lines) == 5
    assert ax_0.lines[0].get_linestyle() == "--"
    assert ax_1.get_title() == "Histogram of imgs values"
    assert len(ax_1.patches) == 5 * 2 * 128
    correlations_1 = plotting.plot_img_comparison(
        target_images, query_images, masker, plot_hist=False)
    assert np.allclose(correlations, correlations_1)
Ejemplo n.º 2
0
    threshold=norm.isf(0.001),
    title='Nilearn Z map of "StopSuccess - Go" (unc p<0.001)',
    plot_abs=False,
    display_mode='ortho')
plotting.plot_glass_brain(
    fsl_z_map,
    colorbar=True,
    threshold=norm.isf(0.001),
    title='FSL Z map of "StopSuccess - Go" (unc p<0.001)',
    plot_abs=False,
    display_mode='ortho')
plt.show()

from nilearn.plotting import plot_img_comparison
plot_img_comparison([z_map], [fsl_z_map],
                    model.masker_,
                    ref_label='Nilearn',
                    src_label='FSL')
plt.show()

#############################################################################
# Simple statistical report of thresholded contrast
# -----------------------------------------------------
# We display the contrast plot and table with cluster information
from nilearn.plotting import plot_contrast_matrix
plot_contrast_matrix('StopSuccess - Go', design_matrix)
plotting.plot_glass_brain(z_map,
                          colorbar=True,
                          threshold=norm.isf(0.001),
                          plot_abs=False,
                          display_mode='z',
                          figure=plt.figure(figsize=(4, 4)))