.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/spatial/test_3d.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_spatial_test_3d.py: Spatial networks: A spatial network in 3D ----------------------------------------- .. only:: html ---- Run this example as a Jupyter notebook: .. card:: :width: 25% :margin: 2 :text-align: center :link: https://lab.ebrains.eu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fnest%2Fnest-simulator-examples&urlpath=lab%2Ftree%2Fnest-simulator-examples%2Fnotebooks%2Fnotebooks%2Fspatial%2Ftest_3d.ipynb&branch=main :link-alt: JupyterHub service .. image:: https://nest-simulator.org/TryItOnEBRAINS.png .. grid:: 1 1 1 1 :padding: 0 0 2 0 .. grid-item:: :class: sd-text-muted :margin: 0 0 3 0 :padding: 0 0 3 0 :columns: 4 See :ref:`our guide ` for more information and troubleshooting. ---- Hans Ekkehard Plesser, UMB .. GENERATED FROM PYTHON SOURCE LINES 28-73 .. code-block:: Python import matplotlib.pyplot as plt import nest nest.ResetKernel() pos = nest.spatial.free(nest.random.uniform(-0.5, 0.5), extent=[1.5, 1.5, 1.5]) l1 = nest.Create("iaf_psc_alpha", 1000, positions=pos) # visualize # extract position information, transpose to list of x, y and z positions xpos, ypos, zpos = zip(*nest.GetPosition(l1)) fig = plt.figure() ax = fig.add_subplot(111, projection="3d") ax.scatter(xpos, ypos, zpos, s=15, facecolor="b") # full connections in box volume [-0.2,0.2]**3 nest.Connect( l1, l1, { "rule": "pairwise_bernoulli", "p": 1.0, "allow_autapses": False, "mask": {"box": {"lower_left": [-0.2, -0.2, -0.2], "upper_right": [0.2, 0.2, 0.2]}}, }, ) # show connections from center element # sender shown in red, targets in green ctr = nest.FindCenterElement(l1) xtgt, ytgt, ztgt = zip(*nest.GetTargetPositions(ctr, l1)[0]) xctr, yctr, zctr = nest.GetPosition(ctr) ax.scatter([xctr], [yctr], [zctr], s=40, facecolor="r") ax.scatter(xtgt, ytgt, ztgt, s=40, facecolor="g", edgecolor="g") tgts = nest.GetTargetNodes(ctr, l1)[0] distances = nest.Distance(ctr, l1) tgt_distances = [d for i, d in enumerate(distances) if i + 1 in tgts] plt.figure() plt.hist(tgt_distances, 25) plt.show() .. _sphx_glr_download_auto_examples_spatial_test_3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: test_3d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: test_3d.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_