{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "815a1030", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from bqplot import Graph, LinearScale, ColorScale, Figure, Tooltip\n", "from ipywidgets import Layout\n", "\n", "np.random.seed(0)\n", "\n", "node_data = list('ABCDEFG')\n", "\n", "#using link matrix to set links\n", "link_matrix = np.zeros((7, 7))\n", "xs = LinearScale()\n", "ys = LinearScale()\n", "cs = ColorScale(scheme='Greens')\n", "x = [100, 200, 200, 300, 300, 300, 300]\n", "y = [2, .5, 4, 8, 6, 4, 1]\n", "graph = Graph(node_data=node_data, link_matrix=link_matrix, link_type='line', \n", " color=np.random.rand(7),\n", " scales={'x': xs, 'y': ys, 'color': cs}, x=x, y=y, \n", " directed=False)\n", "Figure(marks=[graph])" ] }, { "cell_type": "code", "execution_count": null, "id": "241bacd1", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from bqplot import Graph, LinearScale, ColorScale, Figure, Tooltip\n", "from ipywidgets import Layout\n", "\n", "link_data = [{'source': s, 'target': t, 'value': np.random.rand()} for s, t in np.random.randint(0, 7, (20, 2))]\n", "\n", "xs = LinearScale()\n", "ys = LinearScale()\n", "lcs = ColorScale(scheme='Greens')\n", "x = [100, 200, 200, 300, 300, 300, 300]\n", "y = [2, .5, 4, 8, 6, 4, 1]\n", "graph = Graph(node_data=node_data, link_data=link_data, link_type='line',\n", " colors=['orange'], directed=False, \n", " scales={'x': xs, 'y': ys, 'link_color': lcs}, \n", " x=x, y=y, color=np.random.rand(7))\n", "Figure(marks=[graph])" ] } ], "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.2" } }, "nbformat": 4, "nbformat_minor": 5 }