{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Heavy Metal Umlaut\n\n\nExample using unicode strings as graph labels.\n\nAlso shows creative use of the Heavy Metal Umlaut:\nhttps://en.wikipedia.org/wiki/Heavy_metal_umlaut\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 matplotlib.pyplot as plt\nimport networkx as nx\n\ntry:\n    hd = 'H' + unichr(252) + 'sker D' + unichr(252)\n    mh = 'Mot' + unichr(246) + 'rhead'\n    mc = 'M' + unichr(246) + 'tley Cr' + unichr(252) + 'e'\n    st = 'Sp' + unichr(305) + 'n' + unichr(776) + 'al Tap'\n    q = 'Queensr' + unichr(255) + 'che'\n    boc = 'Blue ' + unichr(214) + 'yster Cult'\n    dt = 'Deatht' + unichr(246) + 'ngue'\nexcept NameError:\n    hd = 'H' + chr(252) + 'sker D' + chr(252)\n    mh = 'Mot' + chr(246) + 'rhead'\n    mc = 'M' + chr(246) + 'tley Cr' + chr(252) + 'e'\n    st = 'Sp' + chr(305) + 'n' + chr(776) + 'al Tap'\n    q = 'Queensr' + chr(255) + 'che'\n    boc = 'Blue ' + chr(214) + 'yster Cult'\n    dt = 'Deatht' + chr(246) + 'ngue'\n\nG = nx.Graph()\nG.add_edge(hd, mh)\nG.add_edge(mc, st)\nG.add_edge(boc, mc)\nG.add_edge(boc, dt)\nG.add_edge(st, dt)\nG.add_edge(q, st)\nG.add_edge(dt, mh)\nG.add_edge(st, mh)\n\n# write in UTF-8 encoding\nfh = open('edgelist.utf-8', 'wb')\nfh.write('# -*- coding: utf-8 -*-\\n'.encode('utf-8'))  # encoding hint for emacs\nnx.write_multiline_adjlist(G, fh, delimiter='\\t', encoding='utf-8')\n\n# read and store in UTF-8\nfh = open('edgelist.utf-8', 'rb')\nH = nx.read_multiline_adjlist(fh, delimiter='\\t', encoding='utf-8')\n\nfor n in G.nodes():\n    if n not in H:\n        print(False)\n\nprint(list(G.nodes()))\n\npos = nx.spring_layout(G)\nnx.draw(G, pos, font_size=16, with_labels=False)\nfor p in pos:  # raise text positions\n    pos[p][1] += 0.07\nnx.draw_networkx_labels(G, pos)\nplt.show()"
      ], 
      "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"
      }
    }
  }
}