napari

Classes

Viewer

Napari ndarray viewer.

Functions

napari.view_vectors(data=None, *, ndim=None, features=None, properties=None, property_choices=None, edge_width=1, edge_color='red', edge_color_cycle=None, edge_colormap='viridis', edge_contrast_limits=None, out_of_slice_display=False, length=1, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', visible=True, cache=True, experimental_clipping_planes=None, title='napari', ndisplay=2, order=(), axis_labels=(), show=True) napari.viewer.Viewer[source]

Create a viewer and add a vectors layer.

Parameters
  • data ((N, 2, D) or (N1, N2, ..., ND, D) array) – An (N, 2, D) array is interpreted as “coordinate-like” data and a list of N vectors with start point and projections of the vector in D dimensions. An (N1, N2, …, ND, D) array is interpreted as “image-like” data where there is a length D vector of the projections at each pixel.

  • ndim (int) – Number of dimensions for vectors. When data is not None, ndim must be D. An empty vectors layer can be instantiated with arbitrary ndim.

  • features (dict[str, array-like] or DataFrame) – Features table where each row corresponds to a vector and each column is a feature.

  • properties (dict {str: array (N,)}, DataFrame) – Properties for each vector. Each property should be an array of length N, where N is the number of vectors.

  • property_choices (dict {str: array (N,)}) – possible values for each property.

  • edge_width (float) – Width for all vectors in pixels.

  • length (float) – Multiplicative factor on projections for length of all vectors.

  • edge_color (str) – Color of all of the vectors.

  • edge_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to edge_color if a categorical attribute is used color the vectors.

  • edge_colormap (str, napari.utils.Colormap) – Colormap to set vector color if a continuous attribute is used to set edge_color.

  • edge_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())

  • out_of_slice_display (bool) – If True, renders vectors not just in central plane but also slightly out of slice according to specified point marker size.

  • name (str) – Name of the layer.

  • metadata (dict) – Layer metadata.

  • scale (tuple of float) – Scale factors for the layer.

  • translate (tuple of float) – Translation values for the layer.

  • rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.

  • shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.

  • blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.

  • visible (bool) – Whether the layer visual is currently being displayed.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays. title : string, optional The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

viewer – The newly-created viewer.

Return type

napari.Viewer

napari.view_image(data=None, *, channel_axis=None, rgb=None, colormap=None, contrast_limits=None, gamma=1, interpolation2d='nearest', interpolation3d='linear', rendering='mip', depiction='volume', iso_threshold=0.5, attenuation=0.05, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending=None, visible=True, multiscale=None, cache=True, plane=None, experimental_clipping_planes=None, title='napari', ndisplay=2, order=(), axis_labels=(), show=True) napari.viewer.Viewer[source]

Create a viewer and add an image layer.

Parameters
  • data (array or list of array) – Image data. Can be N >= 2 dimensional. If the last dimension has length 3 or 4 can be interpreted as RGB or RGBA if rgb is True. If a list and arrays are decreasing in shape then the data is treated as a multiscale image. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

  • channel_axis (int, optional) – Axis to expand image along. If provided, each channel in the data will be added as an individual image layer. In channel_axis mode, all other parameters MAY be provided as lists, and the Nth value will be applied to the Nth channel in the data. If a single value is provided, it will be broadcast to all Layers.

  • rgb (bool or list) – Whether the image is rgb RGB or RGBA. If not specified by user and the last dimension of the data has length 3 or 4 it will be set as True. If False the image is interpreted as a luminance image. If a list then must be same length as the axis that is being expanded as channels.

  • colormap (str, napari.utils.Colormap, tuple, dict, list) – Colormaps to use for luminance images. If a string must be the name of a supported colormap from vispy or matplotlib. If a tuple the first value must be a string to assign as a name to a colormap and the second item must be a Colormap. If a dict the key must be a string to assign as a name to a colormap and the value must be a Colormap. If a list then must be same length as the axis that is being expanded as channels, and each colormap is applied to each new image layer.

  • contrast_limits (list (2,)) – Color limits to be used for determining the colormap bounds for luminance images. If not passed is calculated as the min and max of the image. If list of lists then must be same length as the axis that is being expanded and then each colormap is applied to each image.

  • gamma (list, float) – Gamma correction for determining colormap linearity. Defaults to 1. If a list then must be same length as the axis that is being expanded as channels.

  • interpolation (str or list) – Deprecated, to be removed in 0.6.0

  • interpolation2d (str or list) – Interpolation mode used by vispy in 2D. Must be one of our supported modes. If a list then must be same length as the axis that is being expanded as channels.

  • interpolation3d (str or list) – Interpolation mode used by vispy in 3D. Must be one of our supported modes. If a list then must be same length as the axis that is being expanded as channels.

  • rendering (str or list) – Rendering mode used by vispy. Must be one of our supported modes. If a list then must be same length as the axis that is being expanded as channels.

  • depiction (str) –

    Selects a preset volume depiction mode in vispy

    • volume: images are rendered as 3D volumes.

    • plane: images are rendered as 2D planes embedded in 3D.

  • iso_threshold (float or list) – Threshold for isosurface. If a list then must be same length as the axis that is being expanded as channels.

  • attenuation (float or list) – Attenuation rate for attenuated maximum intensity projection. If a list then must be same length as the axis that is being expanded as channels.

  • name (str or list of str) – Name of the layer. If a list then must be same length as the axis that is being expanded as channels.

  • metadata (dict or list of dict) – Layer metadata. If a list then must be a list of dicts with the same length as the axis that is being expanded as channels.

  • scale (tuple of float or list) – Scale factors for the layer. If a list then must be a list of tuples of float with the same length as the axis that is being expanded as channels.

  • translate (tuple of float or list) – Translation values for the layer. If a list then must be a list of tuples of float with the same length as the axis that is being expanded as channels.

  • rotate (float, 3-tuple of float, n-D array or list.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed. If a list then must have same length as the axis that is being expanded as channels.

  • shear (1-D array or list.) – A vector of shear values for an upper triangular n-D shear matrix. If a list then must have same length as the axis that is being expanded as channels.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • opacity (float or list) – Opacity of the layer visual, between 0.0 and 1.0. If a list then must be same length as the axis that is being expanded as channels.

  • blending (str or list) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}. If a list then must be same length as the axis that is being expanded as channels.

  • visible (bool or list of bool) – Whether the layer visual is currently being displayed. If a list then must be same length as the axis that is being expanded as channels.

  • multiscale (bool) – Whether the data is a multiscale image or not. Multiscale data is represented by a list of array like image data. If not specified by the user and if the data is a list of arrays that decrease in shape then it will be taken to be multiscale. The first image in the list should be the largest. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays.

  • plane (dict or SlicingPlane) – Properties defining plane rendering in 3D. Properties are defined in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, ‘thickness’, and ‘enabled’}.

  • experimental_clipping_planes (list of dicts, list of ClippingPlane, or ClippingPlaneList) – Each dict defines a clipping plane in 3D in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, and ‘enabled’}. Values on the negative side of the normal are discarded if the plane is enabled. title : string, optional The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

viewer – The newly-created viewer.

Return type

napari.Viewer

napari.sys_info(as_html=False)[source]

Gathers relevant module versions for troubleshooting purposes.

Parameters

as_html (bool) – if True, info will be returned as HTML, suitable for a QTextEdit widget

napari.view_labels(data, *, num_colors=50, features=None, properties=None, color=None, seed=0.5, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', rendering='iso_categorical', depiction='volume', visible=True, multiscale=None, cache=True, plane=None, experimental_clipping_planes=None, title='napari', ndisplay=2, order=(), axis_labels=(), show=True) napari.viewer.Viewer[source]

Create a viewer and add a labels layer.

Parameters
  • data (array or list of array) – Labels data as an array or multiscale. Must be integer type or bools. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

  • num_colors (int) – Number of unique colors to use in colormap.

  • features (dict[str, array-like] or DataFrame) – Features table where each row corresponds to a label and each column is a feature. The first row corresponds to the background label.

  • properties (dict {str: array (N,)} or DataFrame) – Properties for each label. Each property should be an array of length N, where N is the number of labels, and the first property corresponds to background.

  • color (dict of int to str or array) – Custom label to color mapping. Values must be valid color names or RGBA arrays.

  • seed (float) – Seed for colormap random generator.

  • name (str) – Name of the layer.

  • metadata (dict) – Layer metadata.

  • scale (tuple of float) – Scale factors for the layer.

  • translate (tuple of float) – Translation values for the layer.

  • rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.

  • shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.

  • blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.

  • rendering (str) – 3D Rendering mode used by vispy. Must be one {‘translucent’, ‘iso_categorical’}. ‘translucent’ renders without lighting. ‘iso_categorical’ uses isosurface rendering to calculate lighting effects on labeled surfaces. The default value is ‘iso_categorical’.

  • depiction (str) – 3D Depiction mode. Must be one of {‘volume’, ‘plane’}. The default value is ‘volume’.

  • visible (bool) – Whether the layer visual is currently being displayed.

  • multiscale (bool) – Whether the data is a multiscale image or not. Multiscale data is represented by a list of array like image data. If not specified by the user and if the data is a list of arrays that decrease in shape then it will be taken to be multiscale. The first image in the list should be the largest. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays.

  • plane (dict or SlicingPlane) – Properties defining plane rendering in 3D. Properties are defined in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, ‘thickness’, and ‘enabled’}.

  • experimental_clipping_planes (list of dicts, list of ClippingPlane, or ClippingPlaneList) – Each dict defines a clipping plane in 3D in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, and ‘enabled’}. Values on the negative side of the normal are discarded if the plane is enabled. title : string, optional The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

viewer – The newly-created viewer.

Return type

napari.Viewer

napari.save_layers(path: str, layers: List[Layer], *, plugin: Optional[str] = None, _writer: Optional[WriterContribution] = None) List[str][source]

Write list of layers or individual layer to a path using writer plugins.

If plugin is not provided and only one layer is passed, then we directly call plugin_manager.hook.napari_write_<layer>() which will loop through implementations and stop when the first one returns a non-None result. The order in which implementations are called can be changed with the hook bring_to_front method, for instance: plugin_manager.hook.napari_write_points.bring_to_front

If plugin is not provided and multiple layers are passed, then we call plugin_manager.hook.napari_get_writer() which loops through plugins to find the first one that knows how to handle the combination of layers and is able to write the file. If no plugins offer napari_get_writer for that combination of layers then the builtin napari_get_writer implementation will create a folder and call napari_write_<layer> for each layer using the layer.name variable to modify the path such that the layers are written to unique files in the folder.

If plugin is provided and a single layer is passed, then we call the napari_write_<layer_type> for that plugin, and if it fails we error.

If a plugin is provided and multiple layers are passed, then we call we call napari_get_writer for that plugin, and if it doesn’t return a WriterFunction we error, otherwise we call it and if that fails if it we error.

Parameters
  • path (str) – A filepath, directory, or URL to open.

  • layers (List[layers.Layer]) – Non-empty List of layers to be saved. If only a single layer is passed then we use the hook specification corresponding to its layer type, napari_write_<layer_type>. If multiple layers are passed then we use the napari_get_writer hook specification. Warns when the list of layers is empty.

  • plugin (str, optional) – Name of the plugin to use for saving. If None then all plugins corresponding to appropriate hook specification will be looped through to find the first one that can save the data.

Returns

File paths of any files that were written.

Return type

list of str

napari.view_path(path: PathOrPaths, *, stack: Union[bool, List[List[str]]] = False, plugin: Optional[str] = 'napari', layer_type: Optional[str] = None, title='napari', ndisplay=2, order=(), axis_labels=(), show=True, **kwargs) napari.viewer.Viewer[source]

Create a viewer and add a path layer.

Parameters
  • path (str or list of str) – A filepath, directory, or URL (or a list of any) to open.

  • stack (bool or list[list[str]], optional) – If a list of strings is passed as path and stack is True, then the entire list will be passed to plugins. It is then up to individual plugins to know how to handle a list of paths. If stack is False, then the path list is broken up and passed to plugin readers one by one. by default False. If the stack option is a list of lists containing individual paths, the inner lists are passedto the reader and will be stacked.

  • plugin (str, optional) – Name of a plugin to use, by default builtins. If provided, will force path to be read with the specified plugin. If None, plugin will be read from preferences or inferred if just one reader is compatible. If the requested plugin cannot read path, an exception will be raised.

  • layer_type (str, optional) – If provided, will force data read from path to be passed to the corresponding add_<layer_type> method (along with any additional) kwargs provided to this function. This may result in exceptions if the data returned from the path is not compatible with the layer_type.

  • **kwargs – All other keyword arguments will be passed on to the respective add_layer method. title : string, optional The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

viewer – The newly-created viewer.

Return type

napari.Viewer

napari.view_tracks(data, *, features=None, properties=None, graph=None, tail_width=2, tail_length=30, head_length=0, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending='additive', visible=True, colormap='turbo', color_by='track_id', colormaps_dict=None, cache=True, experimental_clipping_planes=None, title='napari', ndisplay=2, order=(), axis_labels=(), show=True) napari.viewer.Viewer[source]

Create a viewer and add a tracks layer.

Parameters
  • data (array (N, D+1)) – Coordinates for N points in D+1 dimensions. ID,T,(Z),Y,X. The first axis is the integer ID of the track. D is either 3 or 4 for planar or volumetric timeseries respectively.

  • features (Dataframe-like) – Features table where each row corresponds to a point and each column is a feature.

  • properties (dict {str: array (N,)}, DataFrame) – Properties for each point. Each property should be an array of length N, where N is the number of points.

  • graph (dict {int: list}) – Graph representing associations between tracks. Dictionary defines the mapping between a track ID and the parents of the track. This can be one (the track has one parent, and the parent has >=1 child) in the case of track splitting, or more than one (the track has multiple parents, but only one child) in the case of track merging. See examples/tracks_3d_with_graph.py

  • color_by (str) – Track property (from property keys) by which to color vertices.

  • tail_width (float) – Width of the track tails in pixels.

  • tail_length (float) – Length of the positive (backward in time) tails in units of time.

  • head_length (float) – Length of the positive (forward in time) tails in units of time.

  • colormap (str) – Default colormap to use to set vertex colors. Specialized colormaps, relating to specified properties can be passed to the layer via colormaps_dict.

  • colormaps_dict (dict {str: napari.utils.Colormap}) – Optional dictionary mapping each property to a colormap for that property. This allows each property to be assigned a specific colormap, rather than having a global colormap for everything.

  • name (str) – Name of the layer.

  • metadata (dict) – Layer metadata.

  • scale (tuple of float) – Scale factors for the layer.

  • translate (tuple of float) – Translation values for the layer.

  • rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.

  • shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.

  • blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.

  • visible (bool) – Whether the layer visual is currently being displayed.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays. title : string, optional The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

viewer – The newly-created viewer.

Return type

napari.Viewer

napari.current_viewer() Optional[napari.viewer.Viewer][source]

Return the currently active napari viewer.

napari.view_points(data=None, *, ndim=None, features=None, properties=None, text=None, symbol='o', size=10, edge_width=0.05, edge_width_is_relative=True, edge_color='dimgray', edge_color_cycle=None, edge_colormap='viridis', edge_contrast_limits=None, face_color='white', face_color_cycle=None, face_colormap='viridis', face_contrast_limits=None, out_of_slice_display=False, n_dimensional=None, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending='translucent', visible=True, cache=True, property_choices=None, experimental_clipping_planes=None, shading='none', canvas_size_limits=(2, 10000), antialiasing=1, shown=True, title='napari', ndisplay=2, order=(), axis_labels=(), show=True) napari.viewer.Viewer[source]

Create a viewer and add a points layer.

Parameters
  • data (array (N, D)) – Coordinates for N points in D dimensions.

  • ndim (int) – Number of dimensions for shapes. When data is not None, ndim must be D. An empty points layer can be instantiated with arbitrary ndim.

  • features (dict[str, array-like] or DataFrame) – Features table where each row corresponds to a point and each column is a feature.

  • properties (dict {str: array (N,)}, DataFrame) – Properties for each point. Each property should be an array of length N, where N is the number of points.

  • property_choices (dict {str: array (N,)}) – possible values for each property.

  • text (str, dict) – Text to be displayed with the points. If text is set to a key in properties, the value of that property will be displayed. Multiple properties can be composed using f-string-like syntax (e.g., ‘{property_1}, {float_property:.2f}). A dictionary can be provided with keyword arguments to set the text values and display properties. See TextManager.__init__() for the valid keyword arguments. For example usage, see /napari/examples/add_points_with_text.py.

  • symbol (str) – Symbol to be used for the point markers. Must be one of the following: arrow, clobber, cross, diamond, disc, hbar, ring, square, star, tailed_arrow, triangle_down, triangle_up, vbar, x.

  • size (float, array) – Size of the point marker in data pixels. If given as a scalar, all points are made the same size. If given as an array, size must be the same or broadcastable to the same shape as the data.

  • edge_width (float, array) – Width of the symbol edge in pixels.

  • edge_width_is_relative (bool) – If enabled, edge_width is interpreted as a fraction of the point size.

  • edge_color (str, array-like, dict) – Color of the point marker border. Numeric color values should be RGB(A).

  • edge_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to edge_color if a categorical attribute is used color the vectors.

  • edge_colormap (str, napari.utils.Colormap) – Colormap to set edge_color if a continuous attribute is used to set face_color.

  • edge_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())

  • face_color (str, array-like, dict) – Color of the point marker body. Numeric color values should be RGB(A).

  • face_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to face_color if a categorical attribute is used color the vectors.

  • face_colormap (str, napari.utils.Colormap) – Colormap to set face_color if a continuous attribute is used to set face_color.

  • face_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())

  • out_of_slice_display (bool) – If True, renders points not just in central plane but also slightly out of slice according to specified point marker size.

  • n_dimensional (bool) – This property will soon be deprecated in favor of ‘out_of_slice_display’. Use that instead.

  • name (str) – Name of the layer.

  • metadata (dict) – Layer metadata.

  • scale (tuple of float) – Scale factors for the layer.

  • translate (tuple of float) – Translation values for the layer.

  • rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.

  • shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.

  • blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.

  • visible (bool) – Whether the layer visual is currently being displayed.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays.

  • shading (str, Shading) –

    Render lighting and shading on points. Options are:

    • ’none’ No shading is added to the points.

    • ’spherical’ Shading and depth buffer are changed to give a 3D spherical look to the points

  • antialiasing (float) – Amount of antialiasing in canvas pixels.

  • canvas_size_limits (tuple of float) – Lower and upper limits for the size of points in canvas pixels.

  • shown (1-D array of bool) – Whether to show each point. title : string, optional The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

viewer – The newly-created viewer.

Return type

napari.Viewer

napari.imshow(data, *, channel_axis=None, rgb=None, colormap=None, contrast_limits=None, gamma=1, interpolation2d='nearest', interpolation3d='linear', rendering='mip', depiction='volume', iso_threshold=0.5, attenuation=0.05, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending=None, visible=True, multiscale=None, cache=True, plane=None, experimental_clipping_planes=None, viewer=None, title='napari', ndisplay=2, order=(), axis_labels=(), show=True) Tuple[napari.viewer.Viewer, List[napari.layers.image.image.Image]][source]

Load data into an Image layer and return the Viewer and Layer.

Parameters
  • data (array or list of array) – Image data. Can be N >= 2 dimensional. If the last dimension has length 3 or 4 can be interpreted as RGB or RGBA if rgb is True. If a list and arrays are decreasing in shape then the data is treated as a multiscale image. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

  • channel_axis (int, optional) – Axis to expand image along. If provided, each channel in the data will be added as an individual image layer. In channel_axis mode, all other parameters MAY be provided as lists, and the Nth value will be applied to the Nth channel in the data. If a single value is provided, it will be broadcast to all Layers.

  • rgb (bool or list) – Whether the image is rgb RGB or RGBA. If not specified by user and the last dimension of the data has length 3 or 4 it will be set as True. If False the image is interpreted as a luminance image. If a list then must be same length as the axis that is being expanded as channels.

  • colormap (str, napari.utils.Colormap, tuple, dict, list) – Colormaps to use for luminance images. If a string must be the name of a supported colormap from vispy or matplotlib. If a tuple the first value must be a string to assign as a name to a colormap and the second item must be a Colormap. If a dict the key must be a string to assign as a name to a colormap and the value must be a Colormap. If a list then must be same length as the axis that is being expanded as channels, and each colormap is applied to each new image layer.

  • contrast_limits (list (2,)) – Color limits to be used for determining the colormap bounds for luminance images. If not passed is calculated as the min and max of the image. If list of lists then must be same length as the axis that is being expanded and then each colormap is applied to each image.

  • gamma (list, float) – Gamma correction for determining colormap linearity. Defaults to 1. If a list then must be same length as the axis that is being expanded as channels.

  • interpolation (str or list) – Deprecated, to be removed in 0.6.0

  • interpolation2d (str or list) – Interpolation mode used by vispy in 2D. Must be one of our supported modes. If a list then must be same length as the axis that is being expanded as channels.

  • interpolation3d (str or list) – Interpolation mode used by vispy in 3D. Must be one of our supported modes. If a list then must be same length as the axis that is being expanded as channels.

  • rendering (str or list) – Rendering mode used by vispy. Must be one of our supported modes. If a list then must be same length as the axis that is being expanded as channels.

  • depiction (str) –

    Selects a preset volume depiction mode in vispy

    • volume: images are rendered as 3D volumes.

    • plane: images are rendered as 2D planes embedded in 3D.

  • iso_threshold (float or list) – Threshold for isosurface. If a list then must be same length as the axis that is being expanded as channels.

  • attenuation (float or list) – Attenuation rate for attenuated maximum intensity projection. If a list then must be same length as the axis that is being expanded as channels.

  • name (str or list of str) – Name of the layer. If a list then must be same length as the axis that is being expanded as channels.

  • metadata (dict or list of dict) – Layer metadata. If a list then must be a list of dicts with the same length as the axis that is being expanded as channels.

  • scale (tuple of float or list) – Scale factors for the layer. If a list then must be a list of tuples of float with the same length as the axis that is being expanded as channels.

  • translate (tuple of float or list) – Translation values for the layer. If a list then must be a list of tuples of float with the same length as the axis that is being expanded as channels.

  • rotate (float, 3-tuple of float, n-D array or list.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed. If a list then must have same length as the axis that is being expanded as channels.

  • shear (1-D array or list.) – A vector of shear values for an upper triangular n-D shear matrix. If a list then must have same length as the axis that is being expanded as channels.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • opacity (float or list) – Opacity of the layer visual, between 0.0 and 1.0. If a list then must be same length as the axis that is being expanded as channels.

  • blending (str or list) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}. If a list then must be same length as the axis that is being expanded as channels.

  • visible (bool or list of bool) – Whether the layer visual is currently being displayed. If a list then must be same length as the axis that is being expanded as channels.

  • multiscale (bool) – Whether the data is a multiscale image or not. Multiscale data is represented by a list of array like image data. If not specified by the user and if the data is a list of arrays that decrease in shape then it will be taken to be multiscale. The first image in the list should be the largest. Please note multiscale rendering is only supported in 2D. In 3D, only the lowest resolution scale is displayed.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays.

  • plane (dict or SlicingPlane) – Properties defining plane rendering in 3D. Properties are defined in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, ‘thickness’, and ‘enabled’}.

  • experimental_clipping_planes (list of dicts, list of ClippingPlane, or ClippingPlaneList) – Each dict defines a clipping plane in 3D in data coordinates. Valid dictionary keys are {‘position’, ‘normal’, and ‘enabled’}. Values on the negative side of the normal are discarded if the plane is enabled.

  • viewer (Viewer object, optional, by default None.) –

  • title (string, optional) – The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

  • viewer (napari.Viewer) – The created or passed viewer.

  • layer(s) (napari.layers.Image or List[napari.layers.Image]) – The added layer(s). (May be more than one if the channel_axis keyword argument is given.

napari.gui_qt(*, startup_logo=False, gui_exceptions=False, force=False)[source]

Start a Qt event loop in which to run the application.

NOTE: This context manager is deprecated!. Prefer using napari.run().

Parameters
  • startup_logo (bool, optional) – Show a splash screen with the napari logo during startup.

  • gui_exceptions (bool, optional) – Whether to show uncaught exceptions in the GUI, by default they will be shown in the console that launched the event loop.

  • force (bool, optional) – Force the application event_loop to start, even if there are no top level widgets to show.

Notes

This context manager is not needed if running napari within an interactive IPython session. In this case, use the %gui qt magic command, or start IPython with the Qt GUI event loop enabled by default by using ipython --gui=qt.

napari.view_shapes(data=None, *, ndim=None, features=None, properties=None, property_choices=None, text=None, shape_type='rectangle', edge_width=1, edge_color='#777777', edge_color_cycle=None, edge_colormap='viridis', edge_contrast_limits=None, face_color='white', face_color_cycle=None, face_colormap='viridis', face_contrast_limits=None, z_index=0, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=0.7, blending='translucent', visible=True, cache=True, experimental_clipping_planes=None, title='napari', ndisplay=2, order=(), axis_labels=(), show=True) napari.viewer.Viewer[source]

Create a viewer and add a shapes layer.

Parameters
  • data (list or array) – List of shape data, where each element is an (N, D) array of the N vertices of a shape in D dimensions. Can be an 3-dimensional array if each shape has the same number of vertices.

  • ndim (int) – Number of dimensions for shapes. When data is not None, ndim must be D. An empty shapes layer can be instantiated with arbitrary ndim.

  • features (dict[str, array-like] or Dataframe-like) – Features table where each row corresponds to a shape and each column is a feature.

  • properties (dict {str: array (N,)}, DataFrame) – Properties for each shape. Each property should be an array of length N, where N is the number of shapes.

  • property_choices (dict {str: array (N,)}) – possible values for each property.

  • text (str, dict) – Text to be displayed with the shapes. If text is set to a key in properties, the value of that property will be displayed. Multiple properties can be composed using f-string-like syntax (e.g., ‘{property_1}, {float_property:.2f}). A dictionary can be provided with keyword arguments to set the text values and display properties. See TextManager.__init__() for the valid keyword arguments. For example usage, see /napari/examples/add_shapes_with_text.py.

  • shape_type (string or list) – String of shape shape_type, must be one of “{‘line’, ‘rectangle’, ‘ellipse’, ‘path’, ‘polygon’}”. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.

  • edge_width (float or list) – Thickness of lines and edges. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.

  • edge_color (str, array-like) – If string can be any color name recognized by vispy or hex value if starting with #. If array-like must be 1-dimensional array with 3 or 4 elements. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.

  • edge_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to edge_color if a categorical attribute is used color the vectors.

  • edge_colormap (str, napari.utils.Colormap) – Colormap to set edge_color if a continuous attribute is used to set face_color.

  • edge_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())

  • face_color (str, array-like) – If string can be any color name recognized by vispy or hex value if starting with #. If array-like must be 1-dimensional array with 3 or 4 elements. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.

  • face_color_cycle (np.ndarray, list) – Cycle of colors (provided as string name, RGB, or RGBA) to map to face_color if a categorical attribute is used color the vectors.

  • face_colormap (str, napari.utils.Colormap) – Colormap to set face_color if a continuous attribute is used to set face_color.

  • face_contrast_limits (None, (float, float)) – clims for mapping the property to a color map. These are the min and max value of the specified property that are mapped to 0 and 1, respectively. The default value is None. If set the none, the clims will be set to (property.min(), property.max())

  • z_index (int or list) – Specifier of z order priority. Shapes with higher z order are displayed ontop of others. If a list is supplied it must be the same length as the length of data and each element will be applied to each shape otherwise the same value will be used for all shapes.

  • name (str) – Name of the layer.

  • metadata (dict) – Layer metadata.

  • scale (tuple of float) – Scale factors for the layer.

  • translate (tuple of float) – Translation values for the layer.

  • rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.

  • shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.

  • blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.

  • visible (bool) – Whether the layer visual is currently being displayed.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays. title : string, optional The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

viewer – The newly-created viewer.

Return type

napari.Viewer

napari.view_surface(data, *, colormap='gray', contrast_limits=None, gamma=1, name=None, metadata=None, scale=None, translate=None, rotate=None, shear=None, affine=None, opacity=1, blending='translucent', shading='flat', visible=True, cache=True, experimental_clipping_planes=None, wireframe=None, normals=None, title='napari', ndisplay=2, order=(), axis_labels=(), show=True) napari.viewer.Viewer[source]

Create a viewer and add a surface layer.

Parameters
  • data (2-tuple or 3-tuple of array) – The first element of the tuple is an (N, D) array of vertices of mesh triangles. The second is an (M, 3) array of int of indices of the mesh triangles. The optional third element is the (K0, …, KL, N) array of values used to color vertices where the additional L dimensions are used to color the same mesh with different values. If not provided, it defaults to ones.

  • colormap (str, napari.utils.Colormap, tuple, dict) – Colormap to use for luminance images. If a string must be the name of a supported colormap from vispy or matplotlib. If a tuple the first value must be a string to assign as a name to a colormap and the second item must be a Colormap. If a dict the key must be a string to assign as a name to a colormap and the value must be a Colormap.

  • contrast_limits (list (2,)) – Color limits to be used for determining the colormap bounds for luminance images. If not passed is calculated as the min and max of the image.

  • gamma (float) – Gamma correction for determining colormap linearity. Defaults to 1.

  • name (str) – Name of the layer.

  • metadata (dict) – Layer metadata.

  • scale (tuple of float) – Scale factors for the layer.

  • translate (tuple of float) – Translation values for the layer.

  • rotate (float, 3-tuple of float, or n-D array.) – If a float convert into a 2D rotation matrix using that value as an angle. If 3-tuple convert into a 3D rotation matrix, using a yaw, pitch, roll convention. Otherwise assume an nD rotation. Angles are assumed to be in degrees. They can be converted from radians with np.degrees if needed.

  • shear (1-D array or n-D array) – Either a vector of upper triangular values, or an nD shear matrix with ones along the main diagonal.

  • affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

  • opacity (float) – Opacity of the layer visual, between 0.0 and 1.0.

  • blending (str) – One of a list of preset blending modes that determines how RGB and alpha values of the layer visual get mixed. Allowed values are {‘opaque’, ‘translucent’, and ‘additive’}.

  • shading (str, Shading) –

    One of a list of preset shading modes that determine the lighting model using when rendering the surface in 3D.

    • Shading.NONE Corresponds to shading='none'.

    • Shading.FLAT Corresponds to shading='flat'.

    • Shading.SMOOTH Corresponds to shading='smooth'.

  • visible (bool) – Whether the layer visual is currently being displayed.

  • cache (bool) – Whether slices of out-of-core datasets should be cached upon retrieval. Currently, this only applies to dask arrays.

  • wireframe (dict or SurfaceWireframe) – Whether and how to display the edges of the surface mesh with a wireframe.

  • normals (dict or SurfaceNormals) – Whether and how to display the face and vertex normals of the surface mesh. title : string, optional The title of the viewer window. By default ‘napari’.

  • ndisplay ({2, 3}, optional) – Number of displayed dimensions. By default 2.

  • order (tuple of int, optional) – Order in which dimensions are displayed where the last two or last three dimensions correspond to row x column or plane x row x column if ndisplay is 2 or 3. By default None

  • axis_labels (list of str, optional) – Dimension names. By default they are labeled with sequential numbers

  • show (bool, optional) – Whether to show the viewer after instantiation. By default True.

Returns

viewer – The newly-created viewer.

Return type

napari.Viewer

napari.run(*, force=False, gui_exceptions=False, max_loop_level=1, _func_name='run')[source]

Start the Qt Event Loop

Parameters
  • force (bool, optional) – Force the application event_loop to start, even if there are no top level widgets to show.

  • gui_exceptions (bool, optional) – Whether to show uncaught exceptions in the GUI. By default they will be shown in the console that launched the event loop.

  • max_loop_level (int, optional) – The maximum allowable “loop level” for the execution thread. Every time QApplication.exec_() is called, Qt enters the event loop, increments app.thread().loopLevel(), and waits until exit() is called. This function will prevent calling exec_() if the application already has at least max_loop_level event loops running. By default, 1.

  • _func_name (str, optional) – name of calling function, by default ‘run’. This is only here to provide functions like gui_qt a way to inject their name into the warning message.

Raises

RuntimeError – (To avoid confusion) if no widgets would be shown upon starting the event loop.