Shape plot update from Python

Using the graphical user interface to build and exercise models. Includes customizing the GUI by writing a little bit of hoc or Python
Post Reply
ziemek
Posts: 45
Joined: Thu May 23, 2019 8:02 am
Location: Warsaw, Poland
Contact:

Shape plot update from Python

Post 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?
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Shape plot update from Python

Post 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.
ziemek
Posts: 45
Joined: Thu May 23, 2019 8:02 am
Location: Warsaw, Poland
Contact:

Re: Shape plot update from Python

Post by ziemek »

It works straight forward. Thanks!
ziemek
Posts: 45
Joined: Thu May 23, 2019 8:02 am
Location: Warsaw, Poland
Contact:

Re: Shape plot update from Python

Post 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'
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Shape plot update from Python

Post 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
Post Reply