Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/developers/architecture/app_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ Our provider was context dependent. Only when we have an active viewer with a
points layer, can it be provided:

```python
>>> viewer = napari.view_points(name='Some Points')
>>> viewer = napari.Viewer()
>>> viewer.add_points(name='Some Points')

>>> injected_func()
Some Points
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/contributing/documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ from skimage import data
import napari

# create the viewer with an image
viewer = napari.view_image(data.astronaut(), rgb=True)
viewer, layer = napari.imshow(data.astronaut(), rgb=True)

if __name__ == '__main__':
napari.run()
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/contributing/performance/benchmarks.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ViewImageSuite:

def time_view_image(self):
"""Time to view an image."""
self.viewer = napari.view_image(self.data)
self.viewer, _ = napari.imshow(self.data)
```

Here, the creation of the image is completed in the ``setup`` method, and not
Expand Down
6 changes: 4 additions & 2 deletions docs/guides/layers.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ existing layer using the `scale` as a keyword argument or property respectively.

```python
# scaling while creating the image layer
napari.view_image(retina, name='retina', scale=[1,10,1,1])
# scaling an existing layer
viewer, layer = napari.imshow(retina, name='retina', scale=[1,10,1,1])
# scaling an existing layer by accessing from the layer list
viewer.layers['retina'].scale = [1,10,1,1]
# alternatively using the returned layer variable
layer.scale = [1,10,1,1]
```

```{raw} html
Expand Down
6 changes: 3 additions & 3 deletions docs/howtos/extending/magicgui.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def threshold_magic_widget(
return img_as_float(img_layer.data) > threshold

# Create the viewer and add an image
viewer = napari.view_image(data.camera())
viewer, _ = napari.imshow(data.camera())
# Add widget to viewer
viewer.window.add_dock_widget(threshold_magic_widget)
```
Expand Down Expand Up @@ -303,7 +303,7 @@ from napari.layers import Image
def my_widget(image: Image):
...

viewer = napari.view_image(np.random.rand(64, 64), name="My Image")
viewer, _ = napari.imshow(np.random.rand(64, 64), name="My Image")
viewer.window.add_dock_widget(my_widget)
```
*Note the widget on the right side with "My Image" as the currently selected option*
Expand Down Expand Up @@ -508,7 +508,7 @@ def threshold(image: ImageData, threshold: int = 75) -> LabelsData:
"""Threshold an image and return a mask."""
return (image > threshold).astype(int)

viewer = napari.view_image(np.random.randint(0, 100, (64, 64)))
viewer, _ = napari.imshow(np.random.randint(0, 100, (64, 64)))
viewer.window.add_dock_widget(threshold)
threshold() # "call the widget" to call the function, so it shows in the
# screenshot below.
Expand Down
24 changes: 12 additions & 12 deletions docs/howtos/layers/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ The GUI controls may be adjusted as follows:

### A simple example

Create a new viewer and add an image in one go using the {func}`napari.view_image`
Create a new viewer and add an image in one go using the {func}`napari.imshow`
function, or if you already have an existing viewer, add an image to it using
`viewer.add_image`. The API for both methods is the same. In these examples
we'll mainly use `view_image`.
we'll mainly use `imshow`.

A simple example of viewing an image is as follows:

Expand All @@ -112,7 +112,7 @@ import napari
from skimage import data

cells = data.cells3d()[30, 1] # grab some data
viewer = napari.view_image(cells, colormap='magma')
viewer, _ = napari.imshow(cells, colormap='magma')
```

```{code-cell} python
Expand All @@ -129,15 +129,15 @@ nbscreenshot(viewer, alt_text="Cells")
viewer.close()
```

## Arguments of `view_image` and `add_image`
## Arguments of `imshow` and `add_image`

{meth}`~napari.view_layers.view_image` and {meth}`~napari.Viewer.add_image`
{func}`napari.imshow` and {meth}`~napari.Viewer.add_image`
accept the same layer-creation parameters.

```{code-cell} python
:tags: [hide-output]

help(napari.view_image)
help(napari.imshow)
```

## Image data and NumPy-like arrays
Expand Down Expand Up @@ -234,10 +234,10 @@ from skimage import data
cells = data.cells3d() #ZCYX image data

# load multichannel image in one line
viewer = napari.view_image(cells, channel_axis=1)
viewer, layers = napari.imshow(cells, channel_axis=1)

# load multichannel image in one line, with additional options
viewer = napari.view_image(
viewer, layers = napari.imshow(
cells,
channel_axis=1,
name=["membrane", "nuclei"],
Expand Down Expand Up @@ -266,7 +266,7 @@ In this example, the `rgb` keyword is explicitly set to `True` because we know
we are working with an `rgb` image:

```{code-cell} python
viewer = napari.view_image(data.astronaut(), rgb=True)
viewer, layer = napari.imshow(data.astronaut(), rgb=True)
```

```{code-cell} python
Expand Down Expand Up @@ -307,7 +307,7 @@ Pass any of these strings to set the image colormap as shown below:


```{code-cell} python
viewer = napari.view_image(data.moon(), colormap='red')
viewer, layer = napari.imshow(data.moon(), colormap='red')
```

You can also access the current colormap through the `layer.colormap` property
Expand All @@ -331,7 +331,7 @@ from vispy.color import Colormap
cmap = Colormap([[1, 0, 0], [0, 0, 0], [0, 0, 1]])
image = cell()

viewer = napari.view_image(image, colormap=('diverging', cmap))
viewer, layer = napari.imshow(image, colormap=('diverging', cmap))
```

```{code-cell} python
Expand Down Expand Up @@ -374,7 +374,7 @@ an existing layer using the `contrast_limits` keyword argument or property,
respectively.

```{code-cell} python
viewer = napari.view_image(data.moon(), name='moon')
viewer, layer = napari.imshow(data.moon(), name='moon')
viewer.layers['moon'].contrast_limits=(100, 175)
```

Expand Down
18 changes: 8 additions & 10 deletions docs/howtos/layers/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,8 @@ cause the undo history to be reset.
## Controlling the `labels` layer from the console
### A simple example

Create a new viewer and add a labels image in one go using the
{meth}`napari.view_labels` method. If you already have an existing viewer, you
can add a `Labels` image to it using `viewer.add_labels`. The API for both
methods is the same. In these examples we'll mainly use `add_labels` to overlay
Create a new viewer with `napari.Viewer()` and then add a labels image in one go using the {meth}`~napari.Viewer.add_labels` method.
In these examples we'll mainly use `add_labels` to overlay
a `Labels` layer onto on image.

In this example of instance segmentation, we will find and segment each of the
Expand All @@ -441,7 +439,7 @@ cleared = remove_small_objects(clear_border(bw), 20)
label_image = label(cleared)

# create the viewer and add the coins image
viewer = napari.view_image(coins, name='coins')
viewer, _ = napari.imshow(coins, name='coins')
# add the labels
labels_layer = viewer.add_labels(label_image, name='segmentation')
```
Expand All @@ -460,15 +458,15 @@ nbscreenshot(viewer, alt_text="Segmentation of coins in an image, displayed usin
viewer.close()
```

### Arguments of `view_labels` and `add_labels`
### Arguments of `add_labels`

{meth}`~napari.view_layers.view_labels` and {meth}`~napari.Viewer.add_labels`
accept the same layer-creation parameters.
{meth}`~napari.Viewer.add_labels`
accepts the following layer-creation parameters.

```{code-cell} python
:tags: [hide-output]

help(napari.view_labels)
help(napari.Viewer.add_labels)
```

### Labels data
Expand Down Expand Up @@ -534,7 +532,7 @@ from skimage import data
from scipy import ndimage as ndi

blobs = data.binary_blobs(length=128, volume_fraction=0.1, n_dim=3)
viewer = napari.view_image(blobs.astype(float), name='blobs')
viewer, _ = napari.imshow(blobs.astype(float), name='blobs')
labeled = ndi.label(blobs)[0]
labels_layer = viewer.add_labels(labeled, name='blob ID')
viewer.dims.ndisplay = 3
Expand Down
21 changes: 9 additions & 12 deletions docs/howtos/layers/points.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,8 @@ layer:
## Controlling the `points` layer programmatically
### A simple example

You can create a new viewer and add a set of points in one go using the
{meth}`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.
You can create a new viewer with `napari.Viewer()` and add a set of points with the `viewer.add_points` method.
In these examples we'll mainly use `add_points` to overlay points onto an existing image.

Each data point can have annotations associated with it using the
`Points.features` table. These features can be used to set the face and
Expand All @@ -238,7 +235,7 @@ import napari
import numpy as np
from skimage import data

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

points_layer = viewer.add_points(points, size=30)
Expand All @@ -258,15 +255,15 @@ nbscreenshot(viewer, alt_text="3 points overlaid on an astronaut image")
viewer.close()
```

### Arguments of `view_points` and `add_points`
### Arguments of `add_points`

{meth}`~napari.view_layers.view_points` and {meth}`~napari.Viewer.add_points`
accept the same layer-creation parameters.
{meth}`~napari.Viewer.add_points`
accepts the following layer-creation parameters.

```{code-cell} python
:tags: [hide-output]

help(napari.view_points)
help(napari.Viewer.add_points)
```

### Points data
Expand Down Expand Up @@ -403,7 +400,7 @@ To do the same for a face color, substitute `face_color` for `border_color` in t
example snippet below.

```{code-cell} python
viewer = napari.view_image(data.astronaut(), rgb=True)
viewer, _ = napari.imshow(data.astronaut(), rgb=True)
points = np.array([[100, 100], [200, 200], [300, 100]])
point_features = {
'good_point': [True, True, False],
Expand Down Expand Up @@ -448,7 +445,7 @@ colormap on a feature. To do the same for a border color, substitute `face` for
`border`.

```{code-cell} python
viewer = napari.view_image(data.astronaut(), rgb=True)
viewer, _ = napari.imshow(data.astronaut(), rgb=True)
points = np.array([[100, 100], [200, 200], [300, 100]])
point_features = {
'good_point': [True, True, False],
Expand Down
22 changes: 10 additions & 12 deletions docs/howtos/layers/shapes.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,9 @@ are used. i.e. You can't remove a vertex before you have created a shape.
## Controlling the shapes layer programmatically
### A simple example

You can create a new viewer and add a list of shapes in one go using the
{meth}`napari.view_shapes` method, or if you already have an existing viewer,
you can add shapes to it using `viewer.add_shapes`. The API of both methods is
the same. In these examples we'll mainly use `add_shapes` to overlay shapes onto
an existing image.
You can create a new viewer with `napari.Viewer()` and add a list of shapes with the
`viewer.add_shapes` method.
In these examples we'll mainly use `add_shapes` to overlay shapes onto an existing image.

In this example, we will overlay shapes on the image of a photographer:

Expand All @@ -369,7 +367,7 @@ building = np.array([[310, 382], [229, 381], [209, 401], [221, 411],
polygons = [triangle, person, building]

# add the image
viewer = napari.view_image(data.camera(), name='photographer')
viewer, _ = napari.imshow(data.camera(), name='photographer')

# add the polygons
shapes_layer = viewer.add_shapes(
Expand All @@ -395,15 +393,15 @@ nbscreenshot(viewer, alt_text="Shapes overlaid on image")
viewer.close()
```

### Arguments of `view_shapes` and `add_shapes`
### Arguments of `add_shapes`

{meth}`~napari.view_layers.view_shapes` and {meth}`~napari.Viewer.add_shapes`
accept the same layer-creation parameters.
{meth}`~napari.Viewer.add_shapes`
accepts the following layer-creation parameters.

```{code-cell} python
:tags: [hide-output]

help(napari.view_shapes)
help(napari.Viewer.add_shapes)
```

### Shapes data
Expand Down Expand Up @@ -465,7 +463,7 @@ import numpy as np
from skimage import data

# add the image
viewer = napari.view_image(data.camera(), name='photographer')
viewer, _ = napari.imshow(data.camera(), name='photographer')

# create a triangle
triangle = np.array([[11, 13], [111, 113], [22, 246]])
Expand Down Expand Up @@ -513,7 +511,7 @@ import numpy as np
from skimage import data

# add the image
viewer = napari.view_image(data.camera(), name='photographer')
viewer, _ = napari.imshow(data.camera(), name='photographer')

# create some ellipses
ellipse = np.array([[59, 222], [110, 289], [170, 243], [119, 176]])
Expand Down
16 changes: 7 additions & 9 deletions docs/howtos/layers/surface.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ colormap.

## A simple example

You can create a new viewer and add a surface in one go using the
{meth}`napari.view_surface` method, or if you already have an existing viewer,
you can add an image to it using `viewer.add_surface`. The API of both methods
is the same. In these examples we'll mainly use `view_surface`.
You can create a new viewer with `napari.Viewer()` and add a surface using the
{meth}`~napari.Viewer.add_surface` method.

A simple example of viewing a surface follows. You can copy and paste these
statements into the napari console to see how they work:
Expand All @@ -56,7 +54,8 @@ faces = np.array([[0, 1, 2], [1, 2, 3]])
values = np.linspace(0, 1, len(vertices))
surface = (vertices, faces, values)

viewer = napari.view_surface(surface) # add the surface
viewer = napari.Viewer()
viewer.add_surface(surface) # add the surface
```

```{code-cell} python
Expand Down Expand Up @@ -102,15 +101,14 @@ controls are available in the viewer:
section of _Layers at a glance_ for an explanation of each type of blending.
* Shading - Choose `none`, `flat`, or `smooth` from the dropdown.

## Arguments of `view_surface` and `add_surface`
## Arguments of `add_surface`

{meth}`~napari.view_layers.view_surface` and {meth}`~napari.Viewer.add_surface`
accept the same layer-creation parameters.
{meth}`~napari.Viewer.add_surface` accepts the following layer-creation parameters.

```{code-cell} python
:tags: [hide-output]

help(napari.view_surface)
help(napari.Viewer.add_surface)
```

## Surface data
Expand Down
Loading
Loading