{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Paths" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Visualization of paths." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from IPython.display import SVG" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from sknetwork.data import house, cyclic_digraph, star_wars\n", "from sknetwork.visualization import visualize_graph, visualize_bigraph" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Graphs" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "graph = house(True)\n", "adjacency = graph.adjacency\n", "position = graph.position" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "path = [(0, 1), (1, 2), (2, 3)]\n", "edge_labels = [(*edge, 0) for edge in path]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image = visualize_graph(adjacency, position, edge_width=3, edge_labels=edge_labels)\n", "SVG(image)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image = visualize_graph(None, position, edge_width=3, edge_labels=edge_labels)\n", "SVG(image)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Directed graphs" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "graph = cyclic_digraph(10, metadata=True)\n", "adjacency = graph.adjacency\n", "position = graph.position" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "paths = [[(0, 1), (1, 2), (2, 3)], [(6, 7), (7, 8)]]\n", "edge_labels = [(*edge, label) for label, path in enumerate(paths) for edge in path]" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "" ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image = visualize_graph(adjacency, position, width=200, height=None, edge_width=3, edge_labels=edge_labels)\n", "SVG(image)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bipartite graphs" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "graph = star_wars(True)\n", "biadjacency = graph.biadjacency\n", "names_row = graph.names_row\n", "names_col = graph.names_col" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "path = [(0, 1), (2, 1)]\n", "edge_labels = [(*edge, 0) for edge in path]" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "JabbaGreedoVaderBobaA New HopeThe Empire Strikes BackReturn Of The Jedi" ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "image = visualize_bigraph(biadjacency, names_row=names_row, names_col=names_col, edge_width=3, edge_labels=edge_labels)\n", "SVG(image)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.13" } }, "nbformat": 4, "nbformat_minor": 2 }