| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": null, |
| 6 |
"id": "815a1030", |
| 7 |
"metadata": {}, |
| 8 |
"outputs": [], |
| 9 |
"source": [ |
| 10 |
"import numpy as np\n", |
| 11 |
"from bqplot import Graph, LinearScale, ColorScale, Figure, Tooltip\n", |
| 12 |
"from ipywidgets import Layout\n", |
| 13 |
"\n", |
| 14 |
"np.random.seed(0)\n", |
| 15 |
"\n", |
| 16 |
"node_data = list('ABCDEFG')\n", |
| 17 |
"\n", |
| 18 |
"#using link matrix to set links\n", |
| 19 |
"link_matrix = np.zeros((7, 7))\n", |
| 20 |
"xs = LinearScale()\n", |
| 21 |
"ys = LinearScale()\n", |
| 22 |
"cs = ColorScale(scheme='Greens')\n", |
| 23 |
"x = [100, 200, 200, 300, 300, 300, 300]\n", |
| 24 |
"y = [2, .5, 4, 8, 6, 4, 1]\n", |
| 25 |
"graph = Graph(node_data=node_data, link_matrix=link_matrix, link_type='line', \n", |
| 26 |
" color=np.random.rand(7),\n", |
| 27 |
" scales={'x': xs, 'y': ys, 'color': cs}, x=x, y=y, \n", |
| 28 |
" directed=False)\n", |
| 29 |
"Figure(marks=[graph])" |
| 30 |
] |
| 31 |
}, |
| 32 |
{ |
| 33 |
"cell_type": "code", |
| 34 |
"execution_count": null, |
| 35 |
"id": "241bacd1", |
| 36 |
"metadata": {}, |
| 37 |
"outputs": [], |
| 38 |
"source": [ |
| 39 |
"import numpy as np\n", |
| 40 |
"from bqplot import Graph, LinearScale, ColorScale, Figure, Tooltip\n", |
| 41 |
"from ipywidgets import Layout\n", |
| 42 |
"\n", |
| 43 |
"link_data = [{'source': s, 'target': t, 'value': np.random.rand()} for s, t in np.random.randint(0, 7, (20, 2))]\n", |
| 44 |
"\n", |
| 45 |
"xs = LinearScale()\n", |
| 46 |
"ys = LinearScale()\n", |
| 47 |
"lcs = ColorScale(scheme='Greens')\n", |
| 48 |
"x = [100, 200, 200, 300, 300, 300, 300]\n", |
| 49 |
"y = [2, .5, 4, 8, 6, 4, 1]\n", |
| 50 |
"graph = Graph(node_data=node_data, link_data=link_data, link_type='line',\n", |
| 51 |
" colors=['orange'], directed=False, \n", |
| 52 |
" scales={'x': xs, 'y': ys, 'link_color': lcs}, \n", |
| 53 |
" x=x, y=y, color=np.random.rand(7))\n", |
| 54 |
"Figure(marks=[graph])" |
| 55 |
] |
| 56 |
} |
| 57 |
], |
| 58 |
"metadata": { |
| 59 |
"kernelspec": { |
| 60 |
"display_name": "Python 3", |
| 61 |
"language": "python", |
| 62 |
"name": "python3" |
| 63 |
}, |
| 64 |
"language_info": { |
| 65 |
"codemirror_mode": { |
| 66 |
"name": "ipython", |
| 67 |
"version": 3 |
| 68 |
}, |
| 69 |
"file_extension": ".py", |
| 70 |
"mimetype": "text/x-python", |
| 71 |
"name": "python", |
| 72 |
"nbconvert_exporter": "python", |
| 73 |
"pygments_lexer": "ipython3", |
| 74 |
"version": "3.9.2" |
| 75 |
} |
| 76 |
}, |
| 77 |
"nbformat": 4, |
| 78 |
"nbformat_minor": 5 |
| 79 |
} |