def test_plot_surf_stat_map_matplotlib_specific(): mesh = generate_surf() rng = np.random.RandomState(42) data = 10 * rng.standard_normal(size=mesh[0].shape[0]) # Plot to axes axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax) axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax, colorbar=True) fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=False) assert len(fig.axes) == 1 # symmetric_cbar fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=True, symmetric_cbar=True) fig.canvas.draw() assert len(fig.axes) == 2 yticklabels = fig.axes[1].get_yticklabels() first, last = yticklabels[0].get_text(), yticklabels[-1].get_text() assert float(first) == -float(last) # no symmetric_cbar fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=True, symmetric_cbar=False) fig.canvas.draw() assert len(fig.axes) == 2 yticklabels = fig.axes[1].get_yticklabels() first, last = yticklabels[0].get_text(), yticklabels[-1].get_text() assert float(first) != -float(last) # Test handling of nan values in texture data # Add nan values in the texture data[2] = np.nan # Plot the surface stat map fig = plot_surf_stat_map(mesh, stat_map=data) # Check that the resulting plot facecolors contain no transparent faces # (last column equals zero) even though the texture contains nan values assert (mesh[1].shape[0] == ( (fig._axstack.as_list()[0].collections[0]._facecolors[:, 3]) != 0).sum()) # noqa # Save execution time and memory plt.close()
def test_plot_surf_stat_map_error(): mesh = generate_surf() rng = np.random.RandomState(0) data = 10 * rng.randn(mesh[0].shape[0], ) # Try to input vmin with pytest.raises( ValueError, match='this function does not accept a "vmin" argument'): plot_surf_stat_map(mesh, stat_map=data, vmin=0) # Wrong size of stat map data with pytest.raises( ValueError, match='surf_map does not have the same number of vertices'): plot_surf_stat_map(mesh, stat_map=np.hstack((data, data))) with pytest.raises(ValueError, match='surf_map can only have one dimension'): plot_surf_stat_map(mesh, stat_map=np.vstack((data, data)).T)
def test_plot_surf_stat_map(): # Axes3DSubplot has no attribute 'plot_trisurf' for older versions of # matplotlib if LooseVersion(matplotlib.__version__) <= LooseVersion('1.3.1'): raise SkipTest mesh = _generate_surf() rng = np.random.RandomState(0) bg = rng.randn(mesh[0].shape[0], ) data = 10 * rng.randn(mesh[0].shape[0], ) # Plot mesh with stat map plot_surf_stat_map(mesh, stat_map=data) plot_surf_stat_map(mesh, stat_map=data, alpha=1) # Plot mesh with background and stat map plot_surf_stat_map(mesh, stat_map=data, bg_map=bg) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_stat=True, darkness=0.5) # Apply threshold plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_stat=True, darkness=0.5, threshold=0.3) # Change vmax plot_surf_stat_map(mesh, stat_map=data, vmax=5) # Change colormap plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix') # Plot to axes axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax) # Save execution time and memory plt.close()
def test_plot_surf_stat_map(): mesh = _generate_surf() rng = np.random.RandomState(0) bg = rng.randn(mesh[0].shape[0], ) data = 10 * rng.randn(mesh[0].shape[0], ) # Plot mesh with stat map plot_surf_stat_map(mesh, stat_map=data) plot_surf_stat_map(mesh, stat_map=data, colorbar=True) plot_surf_stat_map(mesh, stat_map=data, alpha=1) # Plot mesh with background and stat map plot_surf_stat_map(mesh, stat_map=data, bg_map=bg) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_data=True, darkness=0.5) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5) # Apply threshold plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_data=True, darkness=0.5, threshold=0.3) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5, threshold=0.3) # Change vmax plot_surf_stat_map(mesh, stat_map=data, vmax=5) plot_surf_stat_map(mesh, stat_map=data, vmax=5, colorbar=True) # Change colormap plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix') plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix', colorbar=True) # Plot to axes axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax) axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax, colorbar=True) fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=False) assert len(fig.axes) == 1 # symmetric_cbar fig = plot_surf_stat_map( mesh, stat_map=data, colorbar=True, symmetric_cbar=True) assert len(fig.axes) == 2 yticklabels = fig.axes[1].get_yticklabels() first, last = yticklabels[0].get_text(), yticklabels[-1].get_text() assert float(first) == - float(last) # no symmetric_cbar fig = plot_surf_stat_map( mesh, stat_map=data, colorbar=True, symmetric_cbar=False) assert len(fig.axes) == 2 yticklabels = fig.axes[1].get_yticklabels() first, last = yticklabels[0].get_text(), yticklabels[-1].get_text() assert float(first) != - float(last) # Save execution time and memory plt.close()
def test_plot_surf_stat_map(): mesh = generate_surf() rng = np.random.RandomState(0) bg = rng.randn(mesh[0].shape[0], ) data = 10 * rng.randn(mesh[0].shape[0], ) # Plot mesh with stat map plot_surf_stat_map(mesh, stat_map=data) plot_surf_stat_map(mesh, stat_map=data, colorbar=True) plot_surf_stat_map(mesh, stat_map=data, alpha=1) # Plot mesh with background and stat map plot_surf_stat_map(mesh, stat_map=data, bg_map=bg) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_data=True, darkness=0.5) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5) # Apply threshold plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_data=True, darkness=0.5, threshold=0.3) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5, threshold=0.3) # Change vmax plot_surf_stat_map(mesh, stat_map=data, vmax=5) plot_surf_stat_map(mesh, stat_map=data, vmax=5, colorbar=True) # Change colormap plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix') plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix', colorbar=True) # Plot to axes axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax) axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax, colorbar=True) fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=False) assert len(fig.axes) == 1 # symmetric_cbar fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=True, symmetric_cbar=True) assert len(fig.axes) == 2 yticklabels = fig.axes[1].get_yticklabels() first, last = yticklabels[0].get_text(), yticklabels[-1].get_text() assert float(first) == -float(last) # no symmetric_cbar fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=True, symmetric_cbar=False) assert len(fig.axes) == 2 yticklabels = fig.axes[1].get_yticklabels() first, last = yticklabels[0].get_text(), yticklabels[-1].get_text() assert float(first) != -float(last) # Save execution time and memory plt.close()
def test_plot_surf_stat_map(): # Axes3DSubplot has no attribute 'plot_trisurf' for older versions of # matplotlib if LooseVersion(matplotlib.__version__) <= LooseVersion('1.3.1'): raise SkipTest mesh = _generate_surf() rng = np.random.RandomState(0) bg = rng.randn(mesh[0].shape[0], ) data = 10 * rng.randn(mesh[0].shape[0], ) # Plot mesh with stat map plot_surf_stat_map(mesh, stat_map=data) plot_surf_stat_map(mesh, stat_map=data, alpha=1) # Plot mesh with background and stat map plot_surf_stat_map(mesh, stat_map=data, bg_map=bg) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_stat=True, darkness=0.5) # Apply threshold plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_stat=True, darkness=0.5, threshold=0.3) # Change vmax plot_surf_stat_map(mesh, stat_map=data, vmax=5) # Change colormap plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix') # Plot to axes axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax) # Save execution time and memory plt.close()
def test_plot_surf_stat_map(): mesh = generate_surf() rng = np.random.RandomState(42) bg = rng.standard_normal(size=mesh[0].shape[0]) data = 10 * rng.standard_normal(size=mesh[0].shape[0]) # Plot mesh with stat map plot_surf_stat_map(mesh, stat_map=data) plot_surf_stat_map(mesh, stat_map=data, colorbar=True) plot_surf_stat_map(mesh, stat_map=data, alpha=1) # Plot mesh with background and stat map plot_surf_stat_map(mesh, stat_map=data, bg_map=bg) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_data=True, darkness=0.5) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5) # Apply threshold plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_data=True, darkness=0.5, threshold=0.3) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5, threshold=0.3) # Change colorbar tick format plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5, cbar_tick_format="%.2g") # Change vmax plot_surf_stat_map(mesh, stat_map=data, vmax=5) plot_surf_stat_map(mesh, stat_map=data, vmax=5, colorbar=True) # Change colormap plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix') plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix', colorbar=True) # Plot to axes axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax) axes = plt.subplots(ncols=2, subplot_kw={'projection': '3d'})[1] for ax in axes.flatten(): plot_surf_stat_map(mesh, stat_map=data, ax=ax, colorbar=True) fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=False) assert len(fig.axes) == 1 # symmetric_cbar fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=True, symmetric_cbar=True) fig.canvas.draw() assert len(fig.axes) == 2 yticklabels = fig.axes[1].get_yticklabels() first, last = yticklabels[0].get_text(), yticklabels[-1].get_text() assert float(first) == -float(last) # no symmetric_cbar fig = plot_surf_stat_map(mesh, stat_map=data, colorbar=True, symmetric_cbar=False) fig.canvas.draw() assert len(fig.axes) == 2 yticklabels = fig.axes[1].get_yticklabels() first, last = yticklabels[0].get_text(), yticklabels[-1].get_text() assert float(first) != -float(last) # Test handling of nan values in texture data # Add nan values in the texture data[2] = np.nan # Plot the surface stat map ax = plot_surf_stat_map(mesh, stat_map=data) # Check that the resulting plot facecolors contain no transparent faces # (last column equals zero) even though the texture contains nan values assert (mesh[1].shape[0] == (( ax._axstack.as_list()[0].collections[0]._facecolors[:, 3]) != 0).sum()) # Save execution time and memory plt.close()
def test_plot_surf_stat_map(engine): if not PLOTLY_INSTALLED and engine == "plotly": pytest.skip('Plotly is not installed; required for this test.') mesh = generate_surf() rng = np.random.RandomState(42) bg = rng.standard_normal(size=mesh[0].shape[0]) data = 10 * rng.standard_normal(size=mesh[0].shape[0]) # Plot mesh with stat map plot_surf_stat_map(mesh, stat_map=data, engine=engine) plot_surf_stat_map(mesh, stat_map=data, colorbar=True, engine=engine) plot_surf_stat_map(mesh, stat_map=data, alpha=1, engine=engine) # Plot mesh with background and stat map plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, engine=engine) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_data=True, darkness=0.5, engine=engine) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5, engine=engine) # Plot with title display = plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, title="Stat map title") assert display._suptitle._text == "Stat map title" assert display._suptitle._x == .5 assert display._suptitle._y == .95 # Apply threshold plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, bg_on_data=True, darkness=0.5, threshold=0.3, engine=engine) plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5, threshold=0.3, engine=engine) # Change colorbar tick format plot_surf_stat_map(mesh, stat_map=data, bg_map=bg, colorbar=True, bg_on_data=True, darkness=0.5, cbar_tick_format="%.2g", engine=engine) # Change vmax plot_surf_stat_map(mesh, stat_map=data, vmax=5, engine=engine) plot_surf_stat_map(mesh, stat_map=data, vmax=5, colorbar=True, engine=engine) # Change colormap plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix', engine=engine) plot_surf_stat_map(mesh, stat_map=data, cmap='cubehelix', colorbar=True, engine=engine) plt.close()