# How to plot the 3D morphology of a neuron using 'plot\_morphology()'

**URL:** <https://brian.discourse.group/t/how-to-plot-the-3d-morphology-of-a-neuron-using-plot-morphology/1235>\
**Category:** Support\
**Created:** [11 June 2024 14:02 UTC](https://brian.discourse.group/t/how-to-plot-the-3d-morphology-of-a-neuron-using-plot-morphology/1235 "2024-06-11T14:02:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![czx](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@czx](https://brian.discourse.group/u/czx)\
**Post date:** [11 June 2024 14:02 UTC](https://brian.discourse.group/t/how-to-plot-the-3d-morphology-of-a-neuron-using-plot-morphology/1235/1 "2024-06-11T14:02:50Z")

</div>

Description of problem  
Hi everyone. I tried to see the 3D morphology of a pyramid cell downloaded from `NeuroMorpho.Org`. I used `plot_morphology` with `plot_3d=False` and successfully drew a 2D morphology. But when I altered `False` to `True`, an error returned, see in Traceback. I have no idea about it since I also import the `mayavi` package as suggested in User’s guide.

Minimal code to reproduce problem

```auto
from brian2 import *
from brian2tools import*
from mayavi import*
morpho = Morphology.from_file('neuromorpho//allen cell types//CNG version//H16-06-013-05-06-02_576010060_m_DendriteAxon.CNG.swc')

figure()
plot_morphology(morpho, plot_3d=True, show_compartments= True, show_diameter=True)
show()

```

What you have aready tried  
Checked any package was imported if necessary. Altered `plot_3d=False` to `True` to see the 3D image but failed.

Expected output (if relevant)  
A 3D morphology should be like this (in User’s guide)

 ![image](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/fb70f2581e5c58330535aee1ad2807bbe4579df9.png)

Actual output (if relevant)  
A 2D morphology is available, rather than 3D.

Full traceback of error (if relevant)

```auto
Traceback (most recent call last):
  File "d:\一些文档啥的\2023学年\chengxu\pyramid.py", line 9, in <module>
    plot_morphology(morpho, plot_3d=True, show_compartments= True, show_diameter=True)
  File "D:\python\envs\brain\Lib\site-packages\brian2tools\plotting\morphology.py", line 304, in plot_morphology
    import mayavi.mlab as mayavi
  File "D:\python\envs\brain\Lib\site-packages\mayavi\mlab.py", line 15, in <module>
    from mayavi.core.common import process_ui_events
  File "D:\python\envs\brain\Lib\site-packages\mayavi\core\common.py", line 21, in <module>
    from pyface import api as pyface
  File "D:\python\envs\brain\Lib\site-packages\pyface\api.py", line 13, in <module>
    from .about_dialog import AboutDialog
  File "D:\python\envs\brain\Lib\site-packages\pyface\about_dialog.py", line 15, in <module>
    from .toolkit import toolkit_object
  File "D:\python\envs\brain\Lib\site-packages\pyface\toolkit.py", line 23, in <module>
    toolkit = toolkit_object = find_toolkit("pyface.toolkits")
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python\envs\brain\Lib\site-packages\pyface\base_toolkit.py", line 285, in find_toolkit
    plugin for plugin in importlib_metadata.entry_points()[entry_point]
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^^^^^^^^^^^^^
  File "D:\python\envs\brain\Lib\importlib\metadata\ __init__.py", line 287, in __getitem__
    raise KeyError(name)
KeyError: 'pyface.toolkits'

```

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [11 June 2024 14:12 UTC](https://brian.discourse.group/t/how-to-plot-the-3d-morphology-of-a-neuron-using-plot-morphology/1235/2 "2024-06-11T14:12:27Z")

</div>

Hi @czx. I’ve never seen this error, but it looks like a problem in the `mayavi` installation. Can you run `mayavi2` (cf. [Installation — mayavi 4.8.2 documentation](https://docs.enthought.com/mayavi/mayavi/installation.html#testing-your-installation))?

---

<div class="post-metadata">

**Author:** ![czx](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@czx](https://brian.discourse.group/u/czx)\
**Post date:** [11 June 2024 15:08 UTC](https://brian.discourse.group/t/how-to-plot-the-3d-morphology-of-a-neuron-using-plot-morphology/1235/3 "2024-06-11T15:08:23Z")

</div>

I tried typing ‘matavi2’ in the `cmd` window as described in that documentation, and a similar error was returned, as follows. Should I reinstall `mayavi` ?

```auto
Traceback (most recent call last):
  File "D:\python\envs\brain\Lib\importlib\metadata\ __init__.py", line 285, in __getitem__
    return next(iter(self.select(name=name)))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
StopIteration

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\python\envs\brain\Scripts\mayavi2-script.py", line 6, in <module>
    from mayavi.scripts.mayavi2 import main
  File "D:\python\envs\brain\Lib\site-packages\mayavi\scripts\mayavi2.py", line 462, in <module>
    from mayavi.plugins.app import Mayavi, setup_logger
  File "D:\python\envs\brain\Lib\site-packages\mayavi\plugins\app.py", line 19, in <module>
    from .mayavi_workbench_application import MayaviWorkbenchApplication
  File "D:\python\envs\brain\Lib\site-packages\mayavi\plugins\mayavi_workbench_application.py", line 13, in <module>
    from envisage.ui.workbench.api import WorkbenchApplication
  File "D:\python\envs\brain\Lib\site-packages\envisage\ui\workbench\api.py", line 13, in <module>
    from .workbench import Workbench
  File "D:\python\envs\brain\Lib\site-packages\envisage\ui\workbench\workbench.py", line 14, in <module>
    import pyface.workbench.api as pyface
  File "D:\python\envs\brain\Lib\site-packages\pyface\workbench\api.py", line 13, in <module>
    from .editor import Editor
  File "D:\python\envs\brain\Lib\site-packages\pyface\workbench\editor.py", line 15, in <module>
    from pyface.toolkit import toolkit_object
  File "D:\python\envs\brain\Lib\site-packages\pyface\toolkit.py", line 23, in <module>
    toolkit = toolkit_object = find_toolkit("pyface.toolkits")
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\python\envs\brain\Lib\site-packages\pyface\base_toolkit.py", line 285, in find_toolkit
    plugin for plugin in importlib_metadata.entry_points()[entry_point]
                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^^^^^^^^^^^^^
  File "D:\python\envs\brain\Lib\importlib\metadata\ __init__.py", line 287, in __getitem__
    raise KeyError(name)
KeyError: 'pyface.toolkits'

```

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [11 June 2024 15:10 UTC](https://brian.discourse.group/t/how-to-plot-the-3d-morphology-of-a-neuron-using-plot-morphology/1235/4 "2024-06-11T15:10:41Z")

</div>

Unfortunately, I cannot help much with this. Did you follow the installation instructions on [Installation — mayavi 4.8.2 documentation](https://docs.enthought.com/mayavi/mayavi/installation.html) ?

---

<div class="post-metadata">

**Author:** ![czx](https://avatars.discourse-cdn.com/v4/letter/c/7ba0ec/32.png) [@czx](https://brian.discourse.group/u/czx)\
**Post date:** [14 June 2024 03:18 UTC](https://brian.discourse.group/t/how-to-plot-the-3d-morphology-of-a-neuron-using-plot-morphology/1235/5 "2024-06-14T03:18:04Z")

</div>

I degraded my Python version from 3.12 to 3.7, and reinstalled `mayavi` according to the documentation. Now the problem seems to be solved. I think it’s a version mismatch. Thank you!

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [14 June 2024 08:29 UTC](https://brian.discourse.group/t/how-to-plot-the-3d-morphology-of-a-neuron-using-plot-morphology/1235/6 "2024-06-14T08:29:51Z")

</div>

Happy to hear you solved that issue. Just be aware that Python 3.7 is very old (or was that a typo?) – e.g. the most recent version of Brian2 requires Python 3.10.
