This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.

8.10.17. nilearn.plotting.plot_surf

nilearn.plotting.plot_surf(surf_mesh, surf_map=None, bg_map=None, hemi='left', view='lateral', cmap=None, colorbar=False, avg_method='mean', threshold=None, alpha='auto', bg_on_data=False, darkness=1, vmin=None, vmax=None, cbar_vmin=None, cbar_vmax=None, cbar_tick_format='%.2g', title=None, output_file=None, axes=None, figure=None, **kwargs)[source]

Plotting of surfaces with optional background and data

New in version 0.3.

surf_meshstr or list of two numpy.ndarray or Mesh

Surface mesh geometry, can be a file (valid formats are .gii or Freesurfer specific files such as .orig, .pial, .sphere, .white, .inflated) or a list of two Numpy arrays, the first containing the x-y-z coordinates of the mesh vertices, the second containing the indices (into coords) of the mesh faces, or a Mesh object with “coordinates” and “faces” attributes.

surf_mapstr or numpy.ndarray, optional

Data to be displayed on the surface mesh. Can be a file (valid formats are .gii, .mgz, .nii, .nii.gz, or Freesurfer specific files such as .thickness, .area, .curv, .sulc, .annot, .label) or a Numpy array with a value for each vertex of the surf_mesh.

bg_mapSurface data object (to be defined), optional

Background image to be plotted on the mesh underneath the surf_data in greyscale, most likely a sulcal depth map for realistic shading.

hemi{‘left’, ‘right’}, optional

Hemisphere to display. Default=’left’.

view{‘lateral’, ‘medial’, ‘dorsal’, ‘ventral’, ‘anterior’, ‘posterior’}, optional

View of the surface that is rendered. Default=’lateral’.

cmapmatplotlib.colors.Colormap, or str, optional

The colormap to use. Either a string which is a name of a matplotlib colormap, or a matplotlib colormap object. If None, matplotlib default will be chosen.

colorbarbool, optional

If True, display a colorbar on the right of the plots. Default=False.

avg_method{‘mean’, ‘median’, ‘min’, ‘max’, custom function}, optional

How to average vertex values to derive the face value:

  • mean: results in smooth boundaries

  • median: results in sharp boundaries

  • min or max: for sparse matrices

  • custom function: You can also pass a custom function which will be executed though numpy.apply_along_axis. Here is an example of a custom function:

    def custom_function(vertices):
        return vertices[0] * vertices[1] * vertices[2]


thresholda number or None, default is None.

If None is given, the image is not thresholded. If a number is given, it is used to threshold the image, values below the threshold (in absolute value) are plotted as transparent.

alphafloat or ‘auto’, optional

Alpha level of the mesh (not surf_data). If ‘auto’ is chosen, alpha will default to .5 when no bg_map is passed and to 1 if a bg_map is passed. Default=’auto’.

bg_on_databool, optional

If True, and a bg_map is specified, the surf_data data is multiplied by the background image, so that e.g. sulcal depth is visible beneath the surf_data.


This non-uniformly changes the surf_data values according to e.g the sulcal depth.


darknessfloat between 0 and 1, optional

Specifying the darkness of the background image:

  • ‘1’ indicates that the original values of the background are used

  • ‘.5’ indicates that the background values are reduced by half before being applied.


vminfloat, optional

Lower bound of the colormap. If None, the min of the image is used. Passed to matplotlib.pyplot.imshow.

vmaxfloat, optional

Upper bound of the colormap. If None, the max of the image is used. Passed to matplotlib.pyplot.imshow.

cbar_vmin, cbar_vmaxfloat, float, optional

Lower / upper bounds for the colorbar. If None, the values will be set from the data. Default values are None.

cbar_tick_formatstr, optional

Controls how to format the tick labels of the colorbar. Ex: use “%%.2g” to display using scientific notation. Default=’%.2g’ for scientific notation.

titlestr, or None, optional

The title displayed on the figure. Default=None.

output_filestr, or None, optional

The name of an image file to export the plot to. Valid extensions are .png, .pdf, .svg. If output_file is not None, the plot is saved to a file, and the display is closed.

axesinstance of matplotlib axes, None, optional

The axes instance to plot to. The projection must be ‘3d’ (e.g., figure, axes = plt.subplots(subplot_kw={‘projection’: ‘3d’}), where axes should be passed.). If None, a new axes is created.

figureint, or matplotlib.figure.Figure, or None, optional

Matplotlib figure used or its number. If None is given, a new figure is created.

See also


For surface data object to be used as background map for this plotting function.


For plotting statistical maps on brain surfaces.


for plotting statistical maps on brain surfaces.


For info on the generation of surfaces.