{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import networkx as nx\n", "import panel as pn\n", "\n", "pn.extension(sizing_mode=\"stretch_width\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Panel and NetworkX\n", "\n", "The purpose of this example is to show how easy it is to use [NetworkX](https://networkx.org/documentation/stable/index.html) with Panel. For this example to work you will need `NetworkX>=2.5` and `pygraphviz` installed.\n", "\n", "If you want interactive NetworkX graphs we recommend using [HvPlot](https://hvplot.holoviz.org/index.html). See the [HvPlot NetworkX User Guide](https://hvplot.holoviz.org/user_guide/NetworkX.html)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating a Graph with NetworkX\n", "\n", "This section is independent of Panel. You can find a tutorial and examples in the [NetworkX Documentation](https://networkx.org/documentation/stable/index.html).\n", "\n", "We create the graph via NetworkX. We transform the NetworkX graph to a SVG using pygraphviz." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def clean_svg(svg):\n", " \"\"\"To display a SVG in Panel nicely we need to \n", " \n", " - remove any html in front of the `