Page 1 of 1

Shape plot update from Python

Posted: Mon Dec 02, 2019 1:22 pm
by ziemek
I would like to monitor "cai" variable across shape plot. After I execute this code it shows correctly what I want to monitor, except that it wont update with each steps:

Code: Select all

ps = h.PlotShape(True)
ps.variable('cai')
ps.scale(0, 0.01)
ps.show(0)
ps.exec_menu('Shape Plot')
When I specify the same parameters with mouse - it works and the plot is updates. So how to program it from the Python level?

Re: Shape plot update from Python

Posted: Mon Dec 02, 2019 3:21 pm
by ted
I would like to monitor "cai" variable across shape plot. After I execute this code it shows correctly what I want to monitor, except that it wont update . . .
When I specify the same parameters with mouse - it works and the plot is updates.
The Programmer's Reference documentation of PlotShape shows how to use Python to set up a false color plot, but doesn't show how to make it update automatically during a simulation. That's a pity, because if you're using NEURON's standard run time system, it's very easy to automate PlotShape updates. After your

ps.exec_menu('Shape Plot')

statement, just append the PlotShape to the standard run system's fast_flush_list. For your particular example, this

h.fast_flush_list.append(ps)

should do it.

Re: Shape plot update from Python

Posted: Tue Dec 03, 2019 3:06 am
by ziemek
It works straight forward. Thanks!

Re: Shape plot update from Python

Posted: Tue Feb 01, 2022 8:36 am
by ziemek
If anybody has the same problem I will update this solution with the additional code you need to add before h.fast_flush_list.append(ps):

Code: Select all

h.load_file('stdrun.hoc')
otherwise you will have an error:

Code: Select all

AttributeError: 'hoc.HocObject' object has no attribute 'fast_flush_list'

Re: Shape plot update from Python

Posted: Tue Feb 01, 2022 3:15 pm
by ted
Thanks for clarifying that, ziemek. Readers who are new to NEURON may not know that (1) NEURON has a powerful run time library that takes care of tasks such as updating graphs, but (2) the run time library is loaded only if you tell NEURON to load it. This can be done in several different ways:

0. launching NEURON by executing the command
nrngui

1. executing hoc statements such as
load_file("nrngui.hoc") // which brings up the NEURON Main Menu toolbar
or
load_file("stdrun.hoc") // which doesn't bring up the toolbar
or their Python equivalents

2. executing
from neuron import h, gui