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

plot 05 plotting 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"),
)

plot 05 plotting depth

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

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

Download Python source code: plot_05_plotting_depth.py

Download Jupyter notebook: plot_05_plotting_depth.ipynb

Gallery generated by mkdocs-gallery