napari.layers.Shapes#

class napari.layers.Shapes(data=None, ndim=None, *, affine=None, blending='translucent', cache=True, edge_color='#777777', edge_color_cycle=None, edge_colormap='viridis', edge_contrast_limits=None, edge_width=1, experimental_clipping_planes=None, face_color='white', face_color_cycle=None, face_colormap='viridis', face_contrast_limits=None, feature_defaults=None, features=None, metadata=None, name=None, opacity=0.7, projection_mode='none', properties=None, property_choices=None, rotate=None, scale=None, shape_type='rectangle', shear=None, text=None, translate=None, visible=True, z_index=0)[source]#

Bases: Layer

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.

  • 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.

  • 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’}.

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

  • 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())

  • 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.

  • 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.

  • 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())

  • feature_defaults (dict[str, Any] or Dataframe-like) – The default value of each feature in a table with one row.

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

  • metadata (dict) – Layer metadata.

  • name (str) – Name of the layer.

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

  • projection_mode (str) – How data outside the viewed dimensions but inside the thick Dims slice will be projected onto the viewed dimenions.

  • 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.

  • 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.

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

  • 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.

  • 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.

  • 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.

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

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

  • 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.

data#

List of shape data, where each element is an (N, D) array of the N vertices of a shape in D dimensions.

Type:

(N, ) list of array

features#

Features table where each row corresponds to a shape and each column is a feature.

Type:

Dataframe-like

feature_defaults#

Stores the default value of each feature in a table with one row.

Type:

DataFrame-like

properties#

Properties for each shape. Each property should be an array of length N, where N is the number of shapes.

Type:

dict {str: array (N,)}, DataFrame

text#

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}). For example usage, see /napari/examples/add_shapes_with_text.py.

Type:

str, dict

shape_type#

Name of shape type for each shape.

Type:

(N, ) list of str

edge_color#

Color of the shape border. Numeric color values should be RGB(A).

Type:

str, array-like

face_color#

Color of the shape face. Numeric color values should be RGB(A).

Type:

str, array-like

edge_width#

Edge width for each shape.

Type:

(N, ) list of float

z_index#

z-index for each shape.

Type:

(N, ) list of int

current_edge_width#

Thickness of lines and edges of the next shape to be added or the currently selected shape.

Type:

float

current_edge_color#

Color of the edge of the next shape to be added or the currently selected shape.

Type:

str

current_face_color#

Color of the face of the next shape to be added or the currently selected shape.

Type:

str

selected_data#

List of currently selected shapes.

Type:

set

nshapes#

Total number of shapes.

Type:

int

mode#

Interactive mode. The normal, default mode is PAN_ZOOM, which allows for normal interactivity with the canvas.

The SELECT mode allows for entire shapes to be selected, moved and resized.

The DIRECT mode allows for shapes to be selected and their individual vertices to be moved.

The VERTEX_INSERT and VERTEX_REMOVE modes allow for individual vertices either to be added to or removed from shapes that are already selected. Note that shapes cannot be selected in this mode.

The ADD_RECTANGLE, ADD_ELLIPSE, ADD_LINE, ADD_PATH, and ADD_POLYGON modes all allow for their corresponding shape type to be added.

Type:

Mode

Notes

_data_dictDict of ShapeList

Dictionary containing all the shape data indexed by slice tuple

_data_viewShapeList

Object containing the currently viewed shape data.

_selected_data_historyset

Set of currently selected captured on press of <space>.

_selected_data_storedset

Set of selected previously displayed. Used to prevent rerendering the same highlighted shapes when no data has changed.

_selected_boxNone | np.ndarray

None if no shapes are selected, otherwise a 10x2 array of vertices of the interaction box. The first 8 points are the corners and midpoints of the box. The 9th point is the center of the box, and the last point is the location of the rotation handle that can be used to rotate the box.

_drag_startNone | np.ndarray

If a drag has been started and is in progress then a length 2 array of the initial coordinates of the drag. None otherwise.

_drag_boxNone | np.ndarray

If a drag box is being created to select shapes then this is a 2x2 array of the two extreme corners of the drag. None otherwise.

_drag_box_storedNone | np.ndarray

If a drag box is being created to select shapes then this is a 2x2 array of the two extreme corners of the drag that have previously been rendered. None otherwise. Used to prevent rerendering the same drag box when no data has changed.

_is_movingbool

Bool indicating if any shapes are currently being moved.

_is_selectingbool

Bool indicating if a drag box is currently being created in order to select shapes.

_is_creatingbool

Bool indicating if any shapes are currently being created.

_fixed_aspectbool

Bool indicating if aspect ratio of shapes should be preserved on resizing.

_aspect_ratiofloat

Value of aspect ratio to be preserved if _fixed_aspect is True.

_fixed_vertexNone | np.ndarray

If a scaling or rotation is in progress then a length 2 array of the coordinates that are remaining fixed during the move. None otherwise.

_fixed_indexint

If a scaling or rotation is in progress then the index of the vertex of the bounding box that is remaining fixed during the move. None otherwise.

_update_propertiesbool

Bool indicating if properties are to allowed to update the selected shapes when they are changed. Blocking this prevents circular loops when shapes are selected and the properties are changed based on that selection

_allow_thumbnail_updatebool

Flag set to true to allow the thumbnail to be updated. Blocking the thumbnail can be advantageous where responsiveness is critical.

_clipboarddict

Dict of shape objects that are to be used during a copy and paste.

_colorslist

List of supported vispy color names.

_vertex_sizefloat

Size of the vertices of the shapes and bounding box in Canvas coordinates.

_rotation_handle_lengthfloat

Length of the rotation handle of the bounding box in Canvas coordinates.

_input_ndimint

Dimensions of shape data.

_thumbnail_update_threshint

If there are more than this number of shapes, the thumbnail won’t update during interactive events

inherited-members:

Methods

add(data, *[, shape_type, edge_width, ...])

Add shapes to the current layer.

add_ellipses(data, *[, edge_width, ...])

Add ellipses to the current layer.

add_lines(data, *[, edge_width, edge_color, ...])

Add lines to the current layer.

add_paths(data, *[, edge_width, edge_color, ...])

Add paths to the current layer.

add_polygons(data, *[, edge_width, ...])

Add polygons to the current layer.

add_rectangles(data, *[, edge_width, ...])

Add rectangles to the current layer.

as_layer_data_tuple()

bind_key(key_bind[, func, overwrite])

Bind a key combination to a keymap.

block_thumbnail_update()

Use this context manager to block thumbnail updates

block_update_properties()

click_plane_from_click_data(click_position, ...)

Calculate a (point, normal) plane parallel to the canvas in data coordinates, centered on the centre of rotation of the camera.

create(data[, meta, layer_type])

Create layer from data of type layer_type.

data_to_world(position)

Convert from data coordinates to world coordinates.

get_index_and_intersection(position, ...)

Get the shape index and intersection point of the first shape (i.e., closest to start_point) "under" a mouse click.

get_ray_intersections(position, ...[, world])

Get the start and end point for the ray extending from a point through the data bounding box.

get_source_str()

get_status([position, view_direction, ...])

Status message information of the data at a coordinate position.

get_value(position, *[, view_direction, ...])

Value of the data at a position.

interaction_box(index)

Create the interaction box around a shape or list of shapes.

move_to_back()

Moves selected objects to be displayed behind all others.

move_to_front()

Moves selected objects to be displayed in front of all others.

projected_distance_from_mouse_drag(...)

Calculate the length of the projection of a line between two mouse clicks onto a vector (or array of vectors) in data coordinates.

refresh([event])

Refresh all layer data based on current view slice.

refresh_colors([update_color_mapping])

Calculate and update face and edge colors if using a cycle or color map

refresh_text()

Refresh the text values.

remove_selected()

Remove any selected shapes.

save(path[, plugin])

Save this layer to path with default (or specified) plugin.

set_view_slice()

to_labels([labels_shape])

Return an integer labels image.

to_masks([mask_shape])

Return an array of binary masks, one for each shape.

world_to_data(position)

Convert from world coordinates to data coordinates.

Attributes

ModeCallable

alias of Callable[[Layer, Event], Union[None, Generator[None, None, None]]]

affine

Extra affine transform to go from physical to world coordinates.

blending

Determines how RGB and alpha values get mixed.

bounding_box

class_keymap

current_edge_color

color of shape edges including lines and paths.

current_edge_width

Width of shape edges including lines and paths.

current_face_color

color of shape faces.

current_properties

properties for the next added shape.

cursor

String identifying cursor displayed over canvas.

cursor_size

Size of cursor if custom.

data

Each element is an (N, D) array of the vertices of a shape.

edge_color

Array of RGBA face colors for each shape

edge_color_cycle

Color cycle for edge_color.

edge_color_mode

Edge color setting mode

edge_colormap

Return the colormap to be applied to a property to get the edge color.

edge_contrast_limits

contrast limits for mapping the edge_color colormap property to 0 and 1

edge_width

edge width for each shape.

editable

Whether the current layer data is editable from the viewer.

experimental_clipping_planes

extent

Extent of layer in data and world coordinates.

face_color

Array of RGBA face colors for each shape

face_color_cycle

Color cycle for face_color Can be a list of colors defined by name, RGB or RGBA

face_color_mode

Face color setting mode

face_colormap

Return the colormap to be applied to a property to get the face color.

face_contrast_limits

clims for mapping the face_color colormap property to 0 and 1

feature_defaults

Dataframe-like with one row of feature default values.

features

Dataframe-like features table.

help

displayed in status bar bottom right.

interactive

keymap

loaded

True if this layer is fully loaded in memory, False otherwise.

metadata

Key/value map for user-stored data.

mode

Interactive mode.

mouse_pan

Determine if canvas interactive panning is enabled with the mouse.

mouse_zoom

Determine if canvas interactive zooming is enabled with the mouse.

name

Unique name of the layer.

ndim

Number of dimensions in the data.

nshapes

Total number of shapes.

opacity

Opacity value between 0.0 and 1.0.

projection_mode

Mode of projection of the thick slice onto the viewed dimensions.

properties

Annotations for each shape

property_choices

rotate

Rotation matrix in world coordinates.

scale

Anisotropy factors to scale data into world coordinates.

selected_data

set of currently selected shapes.

shape_type

name of shape type for each shape.

shear

Shear matrix in world coordinates.

source

text

The TextManager object containing the text properties

thumbnail

Integer array of thumbnail for the layer

translate

Factors to shift the layer by in units of world coordinates.

visible

Whether the visual is currently being displayed.

z_index

z_index for each shape.

Details

add(data, *, shape_type='rectangle', edge_width=None, edge_color=None, face_color=None, z_index=None, gui=False)[source]#

Add shapes to the current layer.

Parameters:
  • data (Array | Tuple(Array,str) | List[Array | Tuple(Array, str)] | Tuple(List[Array], str)) – List of shape data, where each element is either an (N, D) array of the N vertices of a shape in D dimensions or a tuple containing an array of the N vertices and the shape_type string. When a shape_type is present, it overrides keyword arg shape_type. Can be an 3-dimensional array if each shape has the same number of vertices.

  • shape_type (string | 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. Overridden by data shape_type, if present.

  • edge_width (float | 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 | tuple | list) – 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 (str | tuple | list) – 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.

  • z_index (int | 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.

  • gui (bool) – Whether the shape is drawn by drawing in the gui.

add_ellipses(data, *, edge_width=None, edge_color=None, face_color=None, z_index=None)[source]#

Add ellipses to the current layer.

Parameters:
  • data (Array | List[Array]) – List of ellipse data where each element is a (4, D) array of 4 vertices in D dimensions representing a bounding box, or in 2D a (2, 2) array of center position and radii magnitudes. Can be a 3-dimensional array for multiple shapes, or list of 2 or 4 vertices for a single shape.

  • edge_width (float | 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 | tuple | list) – 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 (str | tuple | list) – 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.

  • z_index (int | 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.

add_lines(data, *, edge_width=None, edge_color=None, face_color=None, z_index=None)[source]#

Add lines to the current layer.

Parameters:
  • data (Array | List[Array]) – List of line data where each element is a (2, D) array of 2 vertices in D dimensions representing a line. Can be a 3-dimensional array for multiple shapes, or list of 2 vertices for a single shape.

  • edge_width (float | 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 | tuple | list) – 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 (str | tuple | list) – 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.

  • z_index (int | 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.

add_paths(data, *, edge_width=None, edge_color=None, face_color=None, z_index=None)[source]#

Add paths to the current layer.

Parameters:
  • data (Array | List[Array]) – List of path data where each element is a (V, D) array of V vertices in D dimensions representing a path. Can be a 3-dimensional array if all paths have same number of vertices, or a list of V vertices for a single path.

  • edge_width (float | 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 | tuple | list) – 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 (str | tuple | list) – 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.

  • z_index (int | 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.

add_polygons(data, *, edge_width=None, edge_color=None, face_color=None, z_index=None)[source]#

Add polygons to the current layer.

Parameters:
  • data (Array | List[Array]) – List of polygon data where each element is a (V, D) array of V vertices in D dimensions representing a polygon. Can be a 3-dimensional array if polygons have same number of vertices, or a list of V vertices for a single polygon.

  • edge_width (float | 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 | tuple | list) – 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 (str | tuple | list) – 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.

  • z_index (int | 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.

add_rectangles(data, *, edge_width=None, edge_color=None, face_color=None, z_index=None)[source]#

Add rectangles to the current layer.

Parameters:
  • data (Array | List[Array]) – List of rectangle data where each element is a (4, D) array of 4 vertices in D dimensions, or in 2D a (2, 2) array of 2 vertices that are the top-left and bottom-right corners. Can be a 3-dimensional array for multiple shapes, or list of 2 or 4 vertices for a single shape.

  • edge_width (float | 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 | tuple | list) – 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 (str | tuple | list) – 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.

  • z_index (int | 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.

block_thumbnail_update()[source]#

Use this context manager to block thumbnail updates

property current_edge_color#

color of shape edges including lines and paths.

Type:

str

property current_edge_width#

Width of shape edges including lines and paths.

Type:

float

property current_face_color#

color of shape faces.

Type:

str

property current_properties: dict[str, ndarray]#

properties for the next added shape.

Type:

dict{str

Type:

np.ndarray(1,)}

property data#

Each element is an (N, D) array of the vertices of a shape.

Type:

list

property edge_color#

Array of RGBA face colors for each shape

Type:

(N x 4) np.ndarray

property edge_color_cycle: ndarray#

Color cycle for edge_color.

Can be a list of colors defined by name, RGB or RGBA

Type:

Union[list, np.ndarray]

property edge_color_mode: str#

Edge color setting mode

DIRECT (default mode) allows each shape color to be set arbitrarily

CYCLE allows the color to be set via a color cycle over an attribute

COLORMAP allows color to be set via a color map over an attribute

Type:

str

property edge_colormap: Colormap#

Return the colormap to be applied to a property to get the edge color.

Returns:

colormap – The Colormap object.

Return type:

napari.utils.Colormap

property edge_contrast_limits: tuple[float, float] | None#

contrast limits for mapping the edge_color colormap property to 0 and 1

Type:

None, (float, float)

property edge_width#

edge width for each shape.

Type:

list of float

property face_color#

Array of RGBA face colors for each shape

Type:

(N x 4) np.ndarray

property face_color_cycle: ndarray#

Color cycle for face_color Can be a list of colors defined by name, RGB or RGBA

Type:

Union[np.ndarray, cycle]

property face_color_mode: str#

Face color setting mode

DIRECT (default mode) allows each shape color to be set arbitrarily

CYCLE allows the color to be set via a color cycle over an attribute

COLORMAP allows color to be set via a color map over an attribute

Type:

str

property face_colormap: Colormap#

Return the colormap to be applied to a property to get the face color.

Returns:

colormap – The Colormap object.

Return type:

napari.utils.Colormap

property face_contrast_limits: None | tuple[float, float]#

clims for mapping the face_color colormap property to 0 and 1

Type:

None, (float, float)

property feature_defaults#

Dataframe-like with one row of feature default values.

See features for more details on the type of this property.

property features#

Dataframe-like features table.

It is an implementation detail that this is a pandas.DataFrame. In the future, we will target the currently-in-development Data API dataframe protocol [1]. This will enable us to use alternate libraries such as xarray or cuDF for additional features without breaking existing usage of this.

If you need to specifically rely on the pandas API, please coerce this to a pandas.DataFrame using features_to_pandas_dataframe.

References

get_index_and_intersection(position: ndarray, view_direction: ndarray, dims_displayed: list[int]) tuple[float | int | None, ndarray[Any, dtype[ScalarType]] | None][source]#

Get the shape index and intersection point of the first shape (i.e., closest to start_point) “under” a mouse click.

See examples/add_points_on_nD_shapes.py for example usage.

Parameters:
  • position (tuple) – Position in either data or world coordinates.

  • view_direction (Optional[np.ndarray]) – A unit vector giving the direction of the ray in nD world coordinates. The default value is None.

  • dims_displayed (Optional[List[int]]) – A list of the dimensions currently being displayed in the viewer. The default value is None.

Returns:

  • value – The data value along the supplied ray.

  • intersection_point (np.ndarray) – (n,) array containing the point where the ray intersects the first shape (i.e., the shape most in the foreground). The coordinate is in layer coordinates.

interaction_box(index)[source]#

Create the interaction box around a shape or list of shapes. If a single index is passed then the boudning box will be inherited from that shapes interaction box. If list of indices is passed it will be computed directly.

Parameters:

index (int | list) – Index of a single shape, or a list of shapes around which to construct the interaction box

Returns:

box – 10x2 array of vertices of the interaction box. The first 8 points are the corners and midpoints of the box in clockwise order starting in the upper-left corner. The 9th point is the center of the box, and the last point is the location of the rotation handle that can be used to rotate the box

Return type:

np.ndarray

property mode#

Interactive mode. The normal, default mode is PAN_ZOOM, which allows for normal interactivity with the canvas.

The SELECT mode allows for entire shapes to be selected, moved and resized.

The DIRECT mode allows for shapes to be selected and their individual vertices to be moved.

The VERTEX_INSERT and VERTEX_REMOVE modes allow for individual vertices either to be added to or removed from shapes that are already selected. Note that shapes cannot be selected in this mode.

The ADD_RECTANGLE, ADD_ELLIPSE, ADD_LINE, ADD_PATH, and ADD_POLYGON modes all allow for their corresponding shape type to be added.

Type:

MODE

move_to_back() None[source]#

Moves selected objects to be displayed behind all others.

move_to_front() None[source]#

Moves selected objects to be displayed in front of all others.

property nshapes#

Total number of shapes.

Type:

int

property properties: dict[str, ndarray]#

Annotations for each shape

Type:

dict {str

Type:

np.ndarray (N,)}, DataFrame

refresh_colors(update_color_mapping: bool = False)[source]#

Calculate and update face and edge colors if using a cycle or color map

Parameters:

update_color_mapping (bool) – If set to True, the function will recalculate the color cycle map or colormap (whichever is being used). If set to False, the function will use the current color cycle map or color map. For example, if you are adding/modifying shapes and want them to be colored with the same mapping as the other shapes (i.e., the new shapes shouldn’t affect the color cycle map or colormap), set update_color_mapping=False. Default value is False.

refresh_text()[source]#

Refresh the text values.

This is generally used if the properties were updated without changing the data

remove_selected() None[source]#

Remove any selected shapes.

property selected_data#

set of currently selected shapes.

Type:

set

property shape_type#

name of shape type for each shape.

Type:

list of str

property text: TextManager#

The TextManager object containing the text properties

Type:

TextManager

to_labels(labels_shape=None)[source]#

Return an integer labels image.

Parameters:

labels_shape (np.ndarray | tuple | None) – Tuple defining shape of labels image to be generated. If non specified, takes the max of all the vertiecs

Returns:

labels – Integer array where each value is either 0 for background or an integer up to N for points inside the shape at the index value - 1. For overlapping shapes z-ordering will be respected.

Return type:

np.ndarray

to_masks(mask_shape=None)[source]#

Return an array of binary masks, one for each shape.

Parameters:

mask_shape (np.ndarray | tuple | None) – tuple defining shape of mask to be generated. If non specified, takes the max of all the vertices

Returns:

masks – Array where there is one binary mask for each shape

Return type:

np.ndarray

property z_index#

z_index for each shape.

Type:

list of int