{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Pygraphviz Attributes\n\n\nAn example showing how to use the interface to the pygraphviz\nAGraph class to convert to and from graphviz.\n\nAlso see the pygraphviz documentation and examples at\nhttp://pygraphviz.github.io/\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "# Author: Aric Hagberg (hagberg@lanl.gov)\n\n#    Copyright (C) 2006-2017 by\n#    Aric Hagberg <hagberg@lanl.gov>\n#    Dan Schult <dschult@colgate.edu>\n#    Pieter Swart <swart@lanl.gov>\n#    All rights reserved.\n#    BSD license.\n\nimport networkx as nx\n\n# networkx graph\nG = nx.Graph()\n# ad edges with red color\nG.add_edge(1, 2, color='red')\nG.add_edge(2, 3, color='red')\n# add nodes 3 and 4\nG.add_node(3)\nG.add_node(4)\n\n# convert to a graphviz agraph\nA = nx.nx_agraph.to_agraph(G)\n\n# write to dot file\nA.write('k5_attributes.dot')\n\n# convert back to networkx Graph with attributes on edges and\n# default attributes as dictionary data\nX = nx.nx_agraph.from_agraph(A)\nprint(\"edges\")\nprint(list(X.edges(data=True)))\nprint(\"default graph attributes\")\nprint(X.graph)\nprint(\"node node attributes\")\nprint(X.node)"
      ], 
      "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"
      }
    }
  }
}