summaryrefslogtreecommitdiff
path: root/_downloads/13a207a5939541ecfa4ab2ab65ffd8f6/plot_dag_layout.ipynb
diff options
context:
space:
mode:
Diffstat (limited to '_downloads/13a207a5939541ecfa4ab2ab65ffd8f6/plot_dag_layout.ipynb')
-rw-r--r--_downloads/13a207a5939541ecfa4ab2ab65ffd8f6/plot_dag_layout.ipynb54
1 files changed, 54 insertions, 0 deletions
diff --git a/_downloads/13a207a5939541ecfa4ab2ab65ffd8f6/plot_dag_layout.ipynb b/_downloads/13a207a5939541ecfa4ab2ab65ffd8f6/plot_dag_layout.ipynb
new file mode 100644
index 00000000..b690a261
--- /dev/null
+++ b/_downloads/13a207a5939541ecfa4ab2ab65ffd8f6/plot_dag_layout.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# DAG - Topological Layout\n\nThis example combines the `topological_generations` generator with\n`multipartite_layout` to show how to visualize a DAG in topologically-sorted\norder.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": false
+ },
+ "outputs": [],
+ "source": [
+ "import networkx as nx\nimport matplotlib.pyplot as plt\n\n\nG = nx.DiGraph(\n [\n (\"f\", \"a\"),\n (\"a\", \"b\"),\n (\"a\", \"e\"),\n (\"b\", \"c\"),\n (\"b\", \"d\"),\n (\"d\", \"e\"),\n (\"f\", \"c\"),\n (\"f\", \"g\"),\n (\"h\", \"f\"),\n ]\n)\n\nfor layer, nodes in enumerate(nx.topological_generations(G)):\n # `multipartite_layout` expects the layer as a node attribute, so add the\n # numeric layer value as a node attribute\n for node in nodes:\n G.nodes[node][\"layer\"] = layer\n\n# Compute the multipartite_layout using the \"layer\" node attribute\npos = nx.multipartite_layout(G, subset_key=\"layer\")\n\nfig, ax = plt.subplots()\nnx.draw_networkx(G, pos=pos, ax=ax)\nax.set_title(\"DAG layout in topological order\")\nfig.tight_layout()\nplt.show()"
+ ]
+ }
+ ],
+ "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