Skip to content

Note

Click here to download the full example code

Depth-coloring#

This example shows how to color neurons by depth.

The obvious issue with 2d plots is that they are... well, 2d. This means that you can't easily convey depth information. What we can do, however, is color the neuron by depth - that is by the distance to the camera. This is a simple way to give a sense of the neuron's 3d structure.

Note that this currently works only for navis.plot2d, i.e. matplotlib:

import navis
import matplotlib.pyplot as plt

n = navis.example_neurons(1, kind="skeleton")

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

tutorial plotting 05 depth

The depth_coloring parameter will color the neuron by distance from the camera. For this neuron, the ventral dendrites are closest to the camera whereas the dorsal axon is further away.

By default, this will use the jet colormap. You can change this to any of matplotlib's colormaps using the palette parameter:

fig, ax = navis.plot2d(
    n,
    depth_coloring=True,
    palette="hsv",
    method='2d',
    view=("x", "-z"),
)

tutorial plotting 05 depth

This should work with both TreeNeurons and MeshNeurons and methods 2d and 3d.

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

Download Python source code: tutorial_plotting_05_depth.py

Download Jupyter notebook: tutorial_plotting_05_depth.ipynb

Gallery generated by mkdocs-gallery