{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Mayavi2\n\n\nThis is\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "# needs mayavi2\n# run with ipython -wthread\nimport networkx as nx\nimport numpy as np\nfrom mayavi import mlab\nmlab.options.offscreen = True\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)\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(1, bgcolor=(0, 0, 0))\nmlab.clf()\n\npts = mlab.points3d(xyz[:, 0], xyz[:, 1], xyz[:, 2],\n                    scalars,\n                    scale_factor=0.1,\n                    scale_mode='none',\n                    colormap='Blues',\n                    resolution=20)\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))\n\nmlab.savefig('mayavi2_spring.png')\n# mlab.show() # interactive window"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }
  ], 
  "metadata": {
    "kernelspec": {
      "display_name": "Python 2", 
      "name": "python2", 
      "language": "python"
    }, 
    "language_info": {
      "mimetype": "text/x-python", 
      "nbconvert_exporter": "python", 
      "name": "python", 
      "file_extension": ".py", 
      "version": "2.7.12", 
      "pygments_lexer": "ipython2", 
      "codemirror_mode": {
        "version": 2, 
        "name": "ipython"
      }
    }
  }
}