1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
|
.. _rvarplt:
RangeVarPlot
------------
.. class:: RangeVarPlot
Syntax:
``h.RangeVarPlot("rangevar" [, start_segment, stop_segment])``
``h.RangeVarPlot(py_callable [, start_segment, stop_segment])``
Description:
Class for making a space plot. eg. voltage as function of path between
two points on a cell. Specification of the start and stop segments is
optional, but if one is specified both must be specified.
For Interviews plotting, an object of this type needs
to be inserted in a Graph with ``g.addobject(rvp)``. Alternatively, in
NEURON 7.7+, the RangeVarPlot's plot method can be used to plot a snapshot
of the values on a Graph object, a bokeh plot, a matplotlib plot, or anything
with a compatible interface to the last two.
By default, the location of the path nearest the root is location 0
(the origin) of the space plot.
If the *rangevar* does not exist at certain places in the path it
is assumed to have a value of 0.
The first form where *rangevar* is "*v*" or "*m_hh*", etc. is very
efficient since the object can store pointers to the variables
for fast plotting.
The second form is much slower since the expression
must be executed by the interpreter for each point along the path
for each plot. Execution of the expression is equivalent to
\ ``for sec in h.allsec(): for seg in sec: f(seg.x)``
where the expression is the body of f. All section-dependent NEURON
functions will default to the correct section for the call; i.e. there is no need
to say ``sec=`` unless you want to refer to a section that is not the one
whose data is being plotted. The current section may be read via ``h.cas()``.
In NEURON 7.7+, RangeVarPlot's constructor takes optional begin and end arguments.
In Python, these would typically be segments, but they can also be normalized position
on a single segment.
.. seealso::
:func:`distance`, :meth:`Graph.addobject`, :meth:`RangeVarPlot.plot`
Example (plotting by name):
.. code-block::
python
from neuron import h, gui
dend1 = h.Section(name='dend1')
dend2 = h.Section(name='dend2')
for sec in h.allsec():
sec.nseg = sec.L = 501
sec.diam = 1
dend2.connect(dend1)
ic = h.IClamp(dend1(0.5))
ic.amp = 0.5
ic.delay = 0
ic.dur = 1
h.finitialize(-65)
h.continuerun(1)
rvp = h.RangeVarPlot('v', dend1(0), dend2(1))
g = h.Graph()
g.addobject(rvp)
g.size(0, 1002, -70, 50)
.. image:: ../images/rangevarplot1.png
:align: center
Example (plotting a function):
.. code-block::
python
from neuron import h, gui
dend1 = h.Section(name='dend1')
dend2 = h.Section(name='dend2')
for sec in h.allsec():
sec.nseg = sec.L = 501
sec.diam = 1
dend2.connect(dend1)
def my_func(x):
sec = h.cas() # find out which section
if sec == dend1:
y = x ** 2
else:
y = 1 + x ** 2
return y
rvp = h.RangeVarPlot(my_func, dend1(0), dend2(1))
g = h.Graph()
g.addobject(rvp)
g.size(0, 1002, 0, 2)
g.flush()
.. image:: ../images/rangevarplot2.png
:align: center
Example (transfer impedance):
.. code-block::
python
imp = h.Impedance()
rvp = h.RangeVarPlot(imp.transfer)
rvp... #specify range begin and end
imp... #specify impedance computation
g = h.Graph()
g.addobject(rvp)
----
.. method:: RangeVarPlot.plot
Syntax:
``rvp.plot(graph_object)``
``rvp.plot(graph_object, arg1, ..., kwarg1=val1, ...)``
Description:
In NEURON 7.7+, RangeVarPlot.plot plots the current state of the path on any of a number of types of graphs,
including NEURON Graph objects, matplotlib, bokeh, and anything with a .plot or .line method taking x and y values.
Any additional arguments or keyword arguments are passed to the graph's plotting method.
Example:
Plotting to a matplotlib axis (instead of pyplot itself), bokeh, and NEURON's Graph objects and passing optional
arguments to each:
.. code-block::
python
from neuron import h, gui
from matplotlib import pyplot
import bokeh.plotting as b
import math
dend = h.Section(name='dend')
dend.nseg = 55
dend.L = 6.28
#looping over dend.allseg instead of dend to set 0 and 1 ends
for seg in dend.allseg():
seg.v = math.sin(dend.L * seg.x)
r = h.RangeVarPlot('v', dend(0), dend(1)) #Three argument constructor in 7.7+
#matplotlib
graph = pyplot.gca()
r.plot(graph, linewidth=10, color='r')
#NEURON graph
g = h.Graph()
r.plot(g, 2, 3)
g.exec_menu('View = plot')
#Bokeh
bg = b.Figure()
r.plot(bg, line_width=10)
b.show(bg)
pyplot.show()
----
.. method:: RangeVarPlot.begin
Syntax:
``rvp.begin(segment)``
``rvp.begin(x, sec=section)``
Description:
Begins the path for the space plot at the specified segment. Using the first syntax
is recommended in later code; the second is another way to specify the segment ``section(x)``.
.. note::
Beginning with NEURON 7.7, one can also specify the beginning and ending segments in the
RangeVarPlot constructor; e.g. ``rvp = h.RangeVarPlot('v', soma(0), distal(1)``
----
.. method:: RangeVarPlot.end
Syntax:
``rvp.end(segment)``
``rvp.end(x, sec=section)``
Description:
Ends the path for the space plot at the specified segment. Using the first syntax
is recommended in later code; the second is another way to specify the segment ``section(x)``.
.. note::
Beginning with NEURON 7.7, one can also specify the beginning and ending segments in the
RangeVarPlot constructor; e.g. ``rvp = h.RangeVarPlot('v', soma(0), distal(1)``
----
.. method:: RangeVarPlot.origin
Syntax:
``rvp.origin(x, sec=section)``
Description:
Defines the origin (location 0) of the space plot as ``section(x)``.
The default is usually
suitable unless you want to have several rangvarplots in one graph
in which case this function is used to arrange all the plots relative
to each other.
----
.. method:: RangeVarPlot.left
Syntax:
``rvp.left()``
Description:
returns the coordinate of the beginning of the path.
----
.. method:: RangeVarPlot.right
Syntax:
``rvp.right()``
Description:
returns the coordinate of the end of the path. The total length
of the path is ``rvp.right() - rvp.left()``.
----
.. method:: RangeVarPlot.list
Syntax:
``rvp.list(sectionlist)``
Description:
append the path of sections to the :class:`SectionList` object argument.
----
.. method:: RangeVarPlot.color
Syntax:
``rvp.color(index)``
Description:
Change the color property. To see the change on an already plotted
RangeVarPlot in a Graph, the Graph should be :meth:`~Graph.flush`\ ed.
----
.. method:: RangeVarPlot.vector
Syntax:
``yvec = rvp.vector()``
Description:
Copy the range variable values to a new :class:`Vector` yvec.
(``len(yvec)`` will be equal to the number of range points.)
Note:
New in NEURON 8.0.
.. seealso::
:meth:`Graph.addobject`
----
.. method:: RangeVarPlot.to_vector
Syntax:
``rvp.to_vector(yvec)``
``rvp.to_vector(yvec, xvec)``
Description:
Copy the range variable values to the :func:`Vector` yvec. yvec is resized
to the number of range points. If the second arg is present then
the locations are copied to xvec. A plot of \ ``yvec.line(g, xvec)`` would
be identical to a plot using \ ``g.addobject(rvp)``. Returns the number of
range points.
.. seealso::
:meth:`Graph.addobject`
----
.. method:: RangeVarPlot.from_vector
Syntax:
``rvp.from_vector(yvec)``
Description:
Copy the values in yvec to the range variables along the rvp path.
The size of the vector must be consistent with rvp.
|