Using the points layer

In this document, you will learn about the napari Points layer, including displaying spots over an image that have been found in an automated fashion, or manually annotating an image with points. You will also understand how to add a points layer and edit it from the GUI and from the console.

When to use the points layer

The points layer allows you to display an NxD array of N points in D coordinates. You can adjust the size, face color, and edge color of all the points independently. You can also adjust the opactiy, edge width, and symbol representing all the points simultaneously.

Each data point can have annotations associated with it using the dictionary. These properties can be used to set the face and edge colors of the points. For example, when displaying points of different classes/types, one could automatically set color the individual points by their respective class/type. For more details on point properties, see the “setting point edge and face color with properties” below or the point annotation tutorial.

A simple example

You can create a new viewer and add a set of points in one go using the napari.view_points method, or if you already have an existing viewer, you can add points to it using viewer.add_points. The api of both methods is the same. In these examples we’ll mainly use add_points to overlay points onto on an existing image.

In this example, we will overlay some points on the image of an astronaut:

import napari
import numpy as np
from skimage import data

viewer = napari.view_image(data.astronaut(), rgb=True)
points = np.array([[100, 100], [200, 200], [300, 100]])

points_layer = viewer.add_points(points, size=30)
from napari.utils import nbscreenshot

nbscreenshot(viewer, alt_text="3 points overlaid on an astronaut image")