Problem plotting PlotShape

Using the graphical user interface to build and exercise models. Includes customizing the GUI by writing a little bit of hoc or Python
fvarkevisser
Posts: 4
Joined: Tue Sep 21, 2021 3:36 pm

Problem plotting PlotShape

Post by fvarkevisser »

Hi everyone,

I am having trouble plotting a PlotShape in python using pyplot.
Below is a very simple example according to the documentation:

Code: Select all

from neuron import h
from matplotlib import pyplot

main = h.Section(name='main')
dend = h.Section(name='dend')
dend.connect(main)

ps = h.PlotShape(False)
ps.plot(pyplot)
pyplot.show()
Running this gives me the following error:

Code: Select all

Traceback (most recent call last):

  File "path\to\file", line 16, in <module>
    ps.plot(pyplot)

  File "c:\nrn\lib\python\neuron\__init__.py", line 1147, in __call__
    return _do_plot_on_matplotlib_figure(fig)

  File "c:\nrn\lib\python\neuron\__init__.py", line 1005, in _do_plot_on_matplotlib_figure
    variable, varobj, lo, hi, secs = get_plotshape_data(ctypes.py_object(self._data))

OSError: exception: access violation reading 0x0000000000000010
Is there someone who can point out what goes wrong here?

Many thanks!
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Problem plotting PlotShape

Post by ted »

Works for me under CentOS 7 with Python 3.6.8 and NEURON 8.0a-575-gd9462cc master (d9462cc) 2021-05-27 (installed from source code). Also works under Mint 20.1 with Python 3.8 and NEURON 8.0.0 HEAD (429d11ef) 2021-04-30 (installed via pip). That said, both cases generated a MatplotlibDeprecationWarning about "setting the line's pick radius".

What versions of MSWin, NEURON, and Python are you using?
fvarkevisser
Posts: 4
Joined: Tue Sep 21, 2021 3:36 pm

Re: Problem plotting PlotShape

Post by fvarkevisser »

Hi Ted,

Thanks for your reply.
I am running Python 3.9.4 with NEURON 8.0 installed via pip on Windows 10.

I have also tried it on my macOs (Big Sur 11.2.3), running python 3.9.1 and NEURON 8.0.0 installed using pip.
This also gave me an error but actually another one:

Code: Select all

Segmentation fault: 11
I'm not sure if the two errors are related.
fvarkevisser
Posts: 4
Joined: Tue Sep 21, 2021 3:36 pm

Re: Problem plotting PlotShape

Post by fvarkevisser »

On my Mac, I tried running it with python3.7 which worked fine.
So I guess the python version is causing trouble here.
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Problem plotting PlotShape

Post by ted »

Or maybe the problem is with matplotlib. Can you try an earlier Python under MSWin?
fvarkevisser
Posts: 4
Joined: Tue Sep 21, 2021 3:36 pm

Re: Problem plotting PlotShape

Post by fvarkevisser »

Hi Ted,

Trying to run this on Python version 3.6.8 raises the following error:

Code: Select all

>>> from neuron import h
>>> import matplotlib as pyplot
>>> main = h.Section(name='main')
>>> dend = h.Section(name='dend')
>>> dend.connect(main)
dend
>>> ps = h.PlotShape(False)
>>> ps.plot(pyplot)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\nrn\lib\python\neuron\__init__.py", line 1152, in __call__
    raise NotImplementedError
mgiugliano
Posts: 9
Joined: Fri Aug 18, 2006 12:08 pm
Location: Trieste, Italy
Contact:

Re: Problem plotting PlotShape

Post by mgiugliano »

Same problem, under macOs (python 3.9.10) using NEURON 8.0.0 HEAD (429d11ef) 2021-04-30 :-(

I also get the same under Linux (python 3.9.7, same NEURON version).
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Problem plotting PlotShape

Post by ted »

Same problem
Which problem? The first code example

Code: Select all

from neuron import h
from matplotlib import pyplot

main = h.Section(name='main')
dend = h.Section(name='dend')
dend.connect(main)

ps = h.PlotShape(False)
ps.plot(pyplot)
pyplot.show()
works for me, although
ps.plot(pyplot)
does generate this warning:

Code: Select all

/usr/local/lib64/python3.6/site-packages/neuron/__init__.py:904: MatplotlibDeprecationWarning: Setting the line's pick radius via set_picker is deprecated since 3.3 and will be removed two minor releases later; use set_pickradius instead.
  line, = self.plot(xs, ys, zs, '-', **kwargs)
<neuron._PlotShapePlot.__call__.<locals>._get_pyplot_axis3d.<locals>.Axis3DWithNEURON object at 0x7fc8b8d95160>
The second code example, in which
from matplotlib import pyplot
is replaced by
import matplotlib as pyplot
fails upon execution of
ps.plot(pyplot)
with a "NotImplementedError" message (somehow that doesn't seem like a surprise to me).

Which of these two cases is failing for you?
erkan
Posts: 3
Joined: Fri Dec 09, 2022 2:07 am

Re: Problem plotting PlotShape

Post by erkan »

Hi Ted,
I could not solve the problem with the following message plotting ShapePlot plots with plotly or pyplot.
'OSError: exception: access violation reading 0x0000000000000010'

You said in a previous message regarding the same problem:

"Works for me under CentOS 7 with Python 3.6.8 and NEURON 8.0a-575-gd9462cc master (d9462cc) 2021-05-27 (installed from source code). Also works under Mint 20.1 with Python 3.8 and NEURON 8.0.0 HEAD (429d11ef) 2021-04-30 (installed via pip). That said, both cases generated a MatplotlibDeprecationWarning about "setting the line's pick radius".

What versions of MSWin, NEURON, and Python are you using?"

Is it possible for you to describe step by step how to install that version of Neuron with that version of Python?

Best regards,
Erkan
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Problem plotting PlotShape

Post by ted »

I could not solve the problem
Not enough information. Can you provide a specific example, on a toy model (ball and stick would be good), that fails and produces the error message you saw?
Is it possible for you to describe step by step how to install that version of Neuron with that version of Python?
Reversion to an earlier release is almost never the solution to anything. By far, the most common cause of errors generated by execution of user-written code is the user-written code itself, sometimes aided and abetted by documentation that is insufficiently clear. "If you hear hoofbeats in the night, think horses, not zebras."
erkan
Posts: 3
Joined: Fri Dec 09, 2022 2:07 am

Re: Problem plotting PlotShape

Post by erkan »

Hi Ted,
Thank you for your response.
When I run a sample code like this:

from neuron import h
from matplotlib import pyplot
main = h.Section(name='main')
ps = h.PlotShape(False)
ps.plot(pyplot)
pyplot.show()

I get an error message like

Traceback (most recent call last):
File "C:\Users\erkan\OneDrive\Desktop\New folder\dd2.py", line 7, in <module>
ps.plot(pyplot)
File "c:\nrn\lib\python\neuron\__init__.py", line 1076, in __call__
return _do_plot_on_matplotlib_figure(fig)
File "c:\nrn\lib\python\neuron\__init__.py", line 934, in _do_plot_on_matplotlib_figure
variable, varobj, lo, hi, secs = get_plotshape_data(ctypes.py_object(self._data))
OSError: exception: access violation reading 0x0000000000000010

I installed Neuron 7.8 with the Anaconda's latest version as described by the tutorial on https://neuron.yale.edu/ftp/neuron/nrn_ ... nstall.pdf

The problem may have to do with my operating system (Win10 Pro) or something. But, I just hoped that it was due to an installation error. Do you think that the installation procedure described in the tutorial works for recent versions of Neuron as well?

My king regards,
Erkan
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Problem plotting PlotShape

Post by ted »

Hmm, executing this code

Code: Select all

from neuron import h
from matplotlib import pyplot
main = h.Section(name='main')
ps = h.PlotShape(False)
ps.plot(pyplot)
pyplot.show()
doesn't produce an error message for me. You may have discovered a bug. We'll look into this further.
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Problem plotting PlotShape

Post by ramcdougal »

All of that ought to work, but NEURON 7.8 is pretty old. Do you get the same problem in 8.2.2?
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Problem plotting PlotShape

Post by ramcdougal »

This appears to be a Windows-specific problem, but I see the same thing with a development version of NEURON (8.2.2+) and Python 3.11.3 on Windows 10:

Code: Select all

(py311) C:\Users\Robert McDougal>python
Python 3.11.3 | packaged by Anaconda, Inc. | (main, Apr 19 2023, 23:46:34) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import neuron
>>> from neuron import h
>>> soma = h.Section(name="soma")
>>> import matplotlib.pyplot as plt
>>> ps = h.PlotShape(False)
>>> ps.plot(plt)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\nrn\lib\python\neuron\__init__.py", line 1237, in __call__
    return _do_plot_on_matplotlib_figure(fig)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\nrn\lib\python\neuron\__init__.py", line 1083, in _do_plot_on_matplotlib_figure
    variable, varobj, lo, hi, secs = get_plotshape_data(
                                     ^^^^^^^^^^^^^^^^^^^
OSError: exception: access violation reading 0x0000000000000010
>>> neuron.__version__
'8.2.2+'
get_plotshape_data is a very simple function defined at https://github.com/neuronsimulator/nrn/ ... .cpp#L2666

My first thought was that there was some size-of-integer related issue (because that is different in Windows than in mac/linux), but there are no integers involved. There are floats and instead of doubles, but I don't think that's the issue either. We'll have to look into this more.

Two possible short-term workarounds, depending on the nature of what you're trying to do: (1) you could use a cloud Python provider (e.g. Google Colab) and just do a !pip install neuron before you get started) although in that context, I'd use plotly instead of pyplot for a more interactive graph. (2) You could enable the Windows Subsystem for Linux and run NEURON and Python through there.
erkan
Posts: 3
Joined: Fri Dec 09, 2022 2:07 am

Re: Problem plotting PlotShape

Post by erkan »

Hi Ted, Robert
Thank you both for your time.
I'll try the Linux solution.

As a last one. Can we run a 'ses' file on Colab, which is located in a local directory?
Say, is it possible to run a script on Colab:

from neuron import h
import plotly
h.load_file('c91662.ses') # a morphology file
ps = h.PlotShape(False)
ps.plot(plotly).show()

Here, the file 'c91662.ses' is located in "C:\Users\EA\Desktop\Alt_brain".

King regards,
Erkan
Post Reply