Ejemplo n.º 1
0
def test_plot_markers_threshold(threshold, coords):
    """Smoke test for plot_markers with different threshold values."""
    plot_markers([1, 2, 3, 4],
                 coords,
                 node_threshold=threshold,
                 display_mode='x')
    plt.close()
Ejemplo n.º 2
0
def test_plot_markers_tuple_node_coords(coords):
    """Smoke test for plot_markers with node coordinates passed as a list
    of tuples.
    """
    plot_markers([1, 2, 3, 4], [tuple(coord) for coord in coords],
                 display_mode='x')
    plt.close()
Ejemplo n.º 3
0
def test_plot_markers_cmap(cmap, vmin, vmax, coords):
    """Smoke test for plot_markers with different cmaps."""
    plot_markers([1, 2, 3, 4],
                 coords,
                 node_cmap=cmap,
                 node_vmin=vmin,
                 node_vmax=vmax,
                 display_mode='x')
    plt.close()
Ejemplo n.º 4
0
def test_plot_markers_bound_error(vmin, vmax, coords):
    """Tests that a ValueError is raised when vmin and vmax
    have inconsistent values.
    """
    with pytest.raises(ValueError):
        plot_markers([1, 2, 2, 4],
                     coords,
                     node_vmin=vmin,
                     node_vmax=vmax,
                     display_mode='x')
Ejemplo n.º 5
0
def test_plot_markers_node_kwargs(coords):
    """Smoke test for plot_markers testing that node_kwargs is working
    and does not interfere with alpha.
    """
    node_kwargs = dict(marker='s')
    plot_markers([1, 2, 3, 4],
                 coords,
                 alpha=.1,
                 node_kwargs=node_kwargs,
                 display_mode='x')
    plt.close()
Ejemplo n.º 6
0
def test_plot_markers_saving_to_file(coords, tmpdir):
    """Smoke test for plot_markers and file saving."""
    filename = str(tmpdir.join('test.png'))
    display = plot_markers([1, 2, 3, 4],
                           coords,
                           output_file=filename,
                           display_mode='x')
    assert display is None
    assert (os.path.isfile(filename) and os.path.getsize(filename) > 0)
    plt.close()
Ejemplo n.º 7
0
def test_plot_markers_node_sizes_lyrz_display(node_size, coords):
    """Tests for plot_markers and 'lyrz' display mode.

    Tests that markers are plotted with the requested size
    with display_mode='lyrz'. (See issue #3012 and PR #3013).
    """
    display = plot_markers([1, 2, 3, 4],
                           coords,
                           display_mode="lyrz",
                           node_size=node_size)
    for d, axes in display.axes.items():
        display_sizes = axes.ax.collections[0].get_sizes()
        if d == 'l':
            expected_sizes = node_size[-2:]
        elif d == 'r':
            expected_sizes = node_size[:-2]
        else:
            expected_sizes = node_size
        assert np.all(display_sizes == expected_sizes)
    plt.close()
#     Note the 1. on the matrix diagonal: These are the signals variances, set
#     to 1. by the `spheres_masker`. Hence the covariance of the signal is a
#     correlation matrix.

###############################################################################
# Sometimes, the information in the correlation matrix is overwhelming and
# aggregating edge strength from the graph would help. Use the function
# `nilearn.plotting.plot_markers` to visualize this information.

# calculate normalized, absolute strength for each node
node_strength = np.sum(np.abs(matrix), axis=0)
node_strength /= np.max(node_strength)

plotting.plot_markers(
    node_strength,
    coords,
    title='Node strength for absolute value of edges for Power atlas',
)

###############################################################################
# From the correlation matrix, we observe that there is a positive and negative
# structure. We could make two different plots, one for the positive and one for
# the negative structure.

from matplotlib.pyplot import cm

# clip connectivity matrix to preserve positive and negative edges
positive_edges = np.clip(matrix, 0, matrix.max())
negative_edges = np.clip(matrix, matrix.min(), 0)

# calculate strength for positive edges
Ejemplo n.º 9
0
def test_plot_markers_node_sizes(node_size, coords):
    """Smoke test for plot_markers with different node sizes."""
    plot_markers([1, 2, 3, 4], coords, node_size=node_size, display_mode='x')
    plt.close()
Ejemplo n.º 10
0
def test_plot_markers_node_values(node_values, coords):
    """Smoke test for plot_markers with different node values."""
    plot_markers(node_values, coords, display_mode='x')
    plt.close()
Ejemplo n.º 11
0
def test_plot_markers_threshold_errors(coords):
    """Tests that a ValueError is raised when node_threshold is
    higher than the max node_value.
    """
    with pytest.raises(ValueError, match="Provided 'node_threshold' value"):
        plot_markers([1, 2, 2, 4], coords, node_threshold=5, display_mode='x')
Ejemplo n.º 12
0
def test_plot_markers_node_values_errors(coords):
    """Tests that a TypeError is raised when node_values is wrong type."""
    with pytest.raises(TypeError):
        plot_markers(['1', '2', '3', '4'], coords, display_mode='x')
Ejemplo n.º 13
0
def test_plot_markers_dimension_mismatch(matrix, coords):
    """Tests that an error is raised in plot_markers when the length of
    node_values mismatches with node_coords.
    """
    with pytest.raises(ValueError, match="Dimension mismatch"):
        plot_markers(matrix, coords, display_mode='x')