Note
Click here to download the full example code
Skeletons#
Explore skeletons in an interactive 3D viewer - then render what you set up into a figure.
Where plot2d fakes depth, plot3d has a real renderer: proper occlusion, proper perspective, and a camera you can throw around. The trade-off is control - there is no taper, no halo, no linestyle, because those are matplotlib tricks for faking what a 3D renderer just does.
If you have not read the plotting overview yet, start there; colors and palettes work identically in every backend and are covered in coloring.
| Parameter | Effect | octarine | plotly | k3d |
|---|---|---|---|---|
radius | Draw skeletons as tubes rather than lines | |||
linewidth | Line thickness, and the radius scaling factor | |||
soma | Draw the soma as a sphere | |||
connectors | Add synapses as a scatter | |||
snapshot | Render offscreen into a matplotlib figure |
The interactive viewer#
This is what plot3d is for. Hand it neurons and you get a live scene to spin, zoom and pick apart - no parameters required:
import navis
import matplotlib.pyplot as plt
n = navis.example_neurons(1, kind="skeleton")
nl = navis.example_neurons(5, kind="skeleton")
All three backends take the same neuron parameters - what differs is what you get back:
A Viewer object you keep adding to, removing from and recolouring. Fastest, and the only one that works from a plain terminal as well as from Jupyter.
viewer = navis.plot3d(nl, backend="octarine", radius=True)
viewer.set_view("XZ")
An inline figure that persists in the notebook and exports to standalone HTML.
navis.plot3d(nl, backend="plotly", radius=True, legend_orientation="h")
Jupyter-only, in-memory, fast.
navis.plot3d(nl, backend="k3d", radius=True)
Here is the plotly version live - drag to rotate, scroll to zoom, click the legend to hide neurons:
navis.plot3d(nl, backend="plotly", radius=True, legend_orientation="h", height=600)