## Plot vector_y vs vector_x

Using the graphical user interface to build and exercise models. Includes customizing the GUI by writing a little bit of hoc.
mzenker
Posts: 25
Joined: Tue Sep 04, 2018 10:04 am
Location: Germany

### Plot vector_y vs vector_x

Hi,

I want to make a plot using vectors for x and y coordinates. I have built them myself, i.e. they do not figure in the standard NEURON variables. So I don't have access using "plot what?" in a plot window. I have found the vec.plot on the documentation. But how do I build such a plot using the GUI?
I could not search in the forum if this has already been asked since "vector plot GUI" are considered to be too common words by the forum software, see viewtopic.php?f=20&p=17128.

Thank you,
Matthias

ted
Posts: 5742
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

### Re: Plot vector_y vs vector_x

If the x and y values are updated in the course of a simulation, use
NEURON Main Menu / Graph / Phase plane

If you want to plot data that have been recorded to a pair of Vectors in the course of a simulation, you'll need to do that the Vector class's plot method is what you want, and you'll need to generate the plot after the end of a simulation. Example:

Code: Select all

``````// assumptions:
// ivec and vvec are Vectors that record values of some current and voltage
// g is an instance of the Graph class
proc runandplot() {
run()
vvec.plot(g, ivec) // plots vvec values vs. corresponding ivec values
g.exec_menu("View = plot") // optional--automatically rescale x and y axes
}
runandplot()``````
Be sure to read the Programmer's Reference documentation of the Graph and Vector class methods.

mzenker
Posts: 25
Joined: Tue Sep 04, 2018 10:04 am
Location: Germany

### Re: Plot vector_y vs vector_x

Thank you for the quick reply!
ted wrote:
Tue Oct 16, 2018 10:18 am
If the x and y values are updated in the course of a simulation, use
NEURON Main Menu / Graph / Phase plane
That is what I have tried. But I don't manage to display my vectors there. Is there a description somewhere how to do it with the GUI (if possible)?

ted
Posts: 5742
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

### Re: Plot vector_y vs vector_x

NEURON's "phase plane graphs" are not used for plotting vectors. They're just ordinary instances of the Graph class configured to plot traces defined by points at (x,y) coordinates in which the x value comes from an expression that is updated at every advance of a simulation. If you create one with the GUI, you will be prompted to specify the "x axis expression." You should respond by entering an expression that returns a value that is updated at each advance; this could be the name of an existing variable, e.g. time t, membrane potential at some location in a model, or a function. After you do that, you can use the graph's Plot what? tool to specify the expression for whatever you want to use as the y axis coordinate.

Example:
Make a single compartment model that has the hh mechanism.
Create a RunControl Panel and a "Voltage axis graph."
Attach a Point Process Manager, turn it into an IClamp, set its delay to 1 ms and duration to 0.1 ms, and adjust its amp parameter until it's just big enough to trigger an action potential.

Next bring up a Phase Plane graph
NEURON Main Menu / Graph / Phase Plane
Specify the x axis expression to be v (i.e. membrane potential at the middle of your single compartment model).
Use this new Graph's Plot what? tool to add i_cap (membrane capacitive current) as the dependent variable.
Click on Init & Run.
Use the phase plane graph's View = plot to rescale the x and y axes.

Hints and kinks:

1. You don't have to use the GUI to set up a graph that does phase plane plots. Just create an instance of the Graph class and use its xexpr() method to specify what will be used as the x coordinates; read about xexpr in the Programmer's Reference documentation of the Graph class. If you need some more hints, just follow the steps described in the above example, save the configured phase plane graph to a session file, then open the session file with a text editor and you'll see some working code that you can mine for your own use. Suggestion: to learn about mining session files for reusable code, see this topic
How to use hoc to plot a variable vs. time
in the
NEURON hacks
area of the Forum.

2. Did you see that big "Note" in the Python documentation of the Graph class's xexpr method?
"Not that useful in Python; only works with HOC expressions."

That looks like an obsolete caveat. Everything in Python is accessible from hoc, especially the names of variables that would be of interest to display in a phase plane plot (e.g. variables associated with sections and instances of Python-defined cell classes--and it isn't hard to ensure that those variables will have reasonable names in hoc, but that's a subject for a different topic).