Skip to content

Note

Click here to download the full example code

Fine-tuning Skeletons#

In this example we will demonstrate various ways to fine-tune plots with skeletons.

By now, you should already have a basic understanding on how to plot neurons in NAVis (2d vs 3d plots, the various backends and plotting methods, etc.) - if not, check out the plotting tutorial.

We will focus on how to finetune plot2d plots because matplotlib is much more flexible than the plot3d backends when it comes to rendering lines. That said: some of the things we show here will also work for the other backends (Octarine, Vispy and K3d) - just not all.

Radii#

If your skeletons have radii (i.e. there is a non-empty radius column in their .nodes SWC table), you can plot them as tubes instead of lines using the radius parameter. By default, radius is set to False and skeletons are plotted as lines1.

import navis
import matplotlib.pyplot as plt

# Load a neuron
n = navis.example_neurons(1, kind="skeleton")

# Plot as lines
fig, ax = navis.plot2d(n, view=("x", "-z"), method="2d")
plt.tight_layout()

tutorial plotting 04 skeletons

Setting radius=True will plot skeletons as tubes using its nodes' radii information:

fig, ax = navis.plot2d(n, view=("x", "-z"), method="2d", radius=True)
plt.tight_layout()

tutorial plotting 04 skeletons

Line width#

You can change the line width of the skeletons using the linewidth parameter. The default is 1.

fig, ax = navis.plot2d(
    n,
    view=("x", "-z"),
    method="2d",
    radius=False,
    linewidth=2,  # default linewidth is 1
)

tutorial plotting 04 skeletons

linewidth can also be used to scale the size of the tubes when radius=True:

fig, ax = navis.plot2d(
    n,
    view=("x", "-z"),
    method="2d",
    radius=True,
    linewidth=2,  # double the tube radii
)

tutorial plotting 04 skeletons

Line style#

When radius=False, you can change the line style of the skeletons using the linestyle parameter. The default is "-" (i.e. a solid line).

fig, ax = navis.plot2d(
    n,
    view=("x", "-z"),
    method="2d",
    radius=False,
    linewidth=2,
    linestyle="--"  # dashed line
)

tutorial plotting 04 skeletons

The radius and linewidth parameters will also work with plot3d but the linestyle parameter will not.

Total running time of the script: ( 0 minutes 3.133 seconds)

Download Python source code: tutorial_plotting_04_skeletons.py

Download Jupyter notebook: tutorial_plotting_04_skeletons.ipynb

Gallery generated by mkdocs-gallery


  1. This is because plotting tubes can be slow for large number of skeletons.