diff options
Diffstat (limited to '_downloads/35ba6dddd6b6024f6b53a3762807ada7/mayavi2_spring.ipynb')
-rw-r--r-- | _downloads/35ba6dddd6b6024f6b53a3762807ada7/mayavi2_spring.ipynb | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/_downloads/35ba6dddd6b6024f6b53a3762807ada7/mayavi2_spring.ipynb b/_downloads/35ba6dddd6b6024f6b53a3762807ada7/mayavi2_spring.ipynb new file mode 100644 index 00000000..3406ffcb --- /dev/null +++ b/_downloads/35ba6dddd6b6024f6b53a3762807ada7/mayavi2_spring.ipynb @@ -0,0 +1,54 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "%matplotlib inline" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n# Mayavi2\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "import networkx as nx\nimport numpy as np\nfrom mayavi import mlab\n\n# some graphs to try\n# H=nx.krackhardt_kite_graph()\n# H=nx.Graph();H.add_edge('a','b');H.add_edge('a','c');H.add_edge('a','d')\n# H=nx.grid_2d_graph(4,5)\nH = nx.cycle_graph(20)\n\n# reorder nodes from 0,len(G)-1\nG = nx.convert_node_labels_to_integers(H)\n# 3d spring layout\npos = nx.spring_layout(G, dim=3, seed=1001)\n# numpy array of x,y,z positions in sorted node order\nxyz = np.array([pos[v] for v in sorted(G)])\n# scalar colors\nscalars = np.array(list(G.nodes())) + 5\n\nmlab.figure()\n\npts = mlab.points3d(\n xyz[:, 0],\n xyz[:, 1],\n xyz[:, 2],\n scalars,\n scale_factor=0.1,\n scale_mode=\"none\",\n colormap=\"Blues\",\n resolution=20,\n)\n\npts.mlab_source.dataset.lines = np.array(list(G.edges()))\ntube = mlab.pipeline.tube(pts, tube_radius=0.01)\nmlab.pipeline.surface(tube, color=(0.8, 0.8, 0.8))\nmlab.orientation_axes()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.15" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}
\ No newline at end of file |