{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-15T08:37:13.425600Z",
     "start_time": "2019-09-15T08:37:13.418558Z"
    }
   },
   "outputs": [],
   "source": [
    "import networkx as nx\n",
    "G = nx.Graph()\n",
    "options = {\n",
    "    'node_color': 'black',\n",
    "    'node_size': 100,\n",
    "    'width': 3,\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-15T08:39:18.432393Z",
     "start_time": "2019-09-15T08:39:18.410415Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{1, 2, 3}, {'spam'}]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "G = nx.Graph()\n",
    "G.add_edges_from([(1, 2), (1, 3)])\n",
    "G.add_node(\"spam\")       # adds node \"spam\"\n",
    "list(nx.connected_components(G))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-15T08:44:37.228327Z",
     "start_time": "2019-09-15T08:44:36.828326Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 34548 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "G = nx.petersen_graph()\n",
    "plt.subplot(121)\n",
    "nx.draw(G, with_labels=True, font_weight='bold')\n",
    "plt.subplot(122)\n",
    "nx.draw_shell(G, nlist=[range(5, 10), range(5)], with_labels=True, font_weight='bold')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-15T08:46:42.142477Z",
     "start_time": "2019-09-15T08:46:41.871718Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 35160 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from networkx.drawing.nx_pydot import write_dot\n",
    "pos = nx.nx_agraph.graphviz_layout(G)\n",
    "nx.draw(G, pos=pos)\n",
    "write_dot(G, 'file.dot')\n",
    "\n",
    "# $ graph-easy ./spacy-2.1/file.dot --from=dot --as_boxart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-15T08:37:15.713109Z",
     "start_time": "2019-09-15T08:37:15.205482Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/xiaofeiwu/miniconda3/envs/rasa_1x/lib/python3.7/site-packages/networkx/drawing/nx_pylab.py:579: MatplotlibDeprecationWarning: \n",
      "The iterable function was deprecated in Matplotlib 3.1 and will be removed in 3.3. Use np.iterable instead.\n",
      "  if not cb.iterable(width):\n"
     ]
    }
   ],
   "source": [
    "G = nx.dodecahedral_graph()\n",
    "shells = [[2, 3, 4, 5, 6], [8, 1, 0, 19, 18, 17, 16, 15, 14, 7], [9, 10, 11, 12, 13]]\n",
    "nx.draw_shell(G, nlist=shells, **options)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-09-15T08:40:34.653031Z",
     "start_time": "2019-09-15T08:40:34.190783Z"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 35160 characters]\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from networkx.drawing.nx_pydot import write_dot\n",
    "pos = nx.nx_agraph.graphviz_layout(G)\n",
    "nx.draw(G, pos=pos)\n",
    "write_dot(G, 'file.dot')"
   ]
  }
 ],
 "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.7.3"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
