{ "cells": [ { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import networkx as nx\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from bokeh.io import output_notebook, show, save\n", "from bokeh.models import Range1d, Circle, ColumnDataSource, MultiLine\n", "from bokeh.plotting import figure\n", "from bokeh.plotting import from_networkx\n", "from bokeh.palettes import Blues8, Reds8, Purples8, Oranges8, Viridis8, Spectral8\n", "from bokeh.transform import linear_cmap\n", "from pathlib import Path" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " \n", " Loading BokehJS ...\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": "(function(root) {\n function now() {\n return new Date();\n }\n\n const force = true;\n\n if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\nconst JS_MIME_TYPE = 'application/javascript';\n const HTML_MIME_TYPE = 'text/html';\n const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n const CLASS_NAME = 'output_bokeh rendered_html';\n\n /**\n * Render data to the DOM node\n */\n function render(props, node) {\n const script = document.createElement(\"script\");\n node.appendChild(script);\n }\n\n /**\n * Handle when an output is cleared or removed\n */\n function handleClearOutput(event, handle) {\n const cell = handle.cell;\n\n const id = cell.output_area._bokeh_element_id;\n const server_id = cell.output_area._bokeh_server_id;\n // Clean up Bokeh references\n if (id != null && id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n\n if (server_id !== undefined) {\n // Clean up Bokeh references\n const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n cell.notebook.kernel.execute(cmd_clean, {\n iopub: {\n output: function(msg) {\n const id = msg.content.text.trim();\n if (id in Bokeh.index) {\n Bokeh.index[id].model.document.clear();\n delete Bokeh.index[id];\n }\n }\n }\n });\n // Destroy server and session\n const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n cell.notebook.kernel.execute(cmd_destroy);\n }\n }\n\n /**\n * Handle when a new output is added\n */\n function handleAddOutput(event, handle) {\n const output_area = handle.output_area;\n const output = handle.output;\n\n // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n return\n }\n\n const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n\n if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n // store reference to embed id on output_area\n output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n }\n if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n const bk_div = document.createElement(\"div\");\n bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n const script_attrs = bk_div.children[0].attributes;\n for (let i = 0; i < script_attrs.length; i++) {\n toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n }\n // store reference to server id on output_area\n output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n }\n }\n\n function register_renderer(events, OutputArea) {\n\n function append_mime(data, metadata, element) {\n // create a DOM node to render to\n const toinsert = this.create_output_subarea(\n metadata,\n CLASS_NAME,\n EXEC_MIME_TYPE\n );\n this.keyboard_manager.register_events(toinsert);\n // Render to node\n const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n render(props, toinsert[toinsert.length - 1]);\n element.append(toinsert);\n return toinsert\n }\n\n /* Handle when an output is cleared or removed */\n events.on('clear_output.CodeCell', handleClearOutput);\n events.on('delete.Cell', handleClearOutput);\n\n /* Handle when a new output is added */\n events.on('output_added.OutputArea', handleAddOutput);\n\n /**\n * Register the mime type and append_mime function with output_area\n */\n OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n /* Is output safe? */\n safe: true,\n /* Index of renderer in `output_area.display_order` */\n index: 0\n });\n }\n\n // register the mime type if in Jupyter Notebook environment and previously unregistered\n if (root.Jupyter !== undefined) {\n const events = require('base/js/events');\n const OutputArea = require('notebook/js/outputarea').OutputArea;\n\n if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n register_renderer(events, OutputArea);\n }\n }\n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n const NB_LOAD_WARNING = {'data': {'text/html':\n \"
\\n\"+\n \"

\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"

\\n\"+\n \"\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"
\"}};\n\n function display_loaded() {\n const el = document.getElementById(\"1004\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) {\n if (callback != null)\n callback();\n });\n } finally {\n delete root._bokeh_onload_callbacks\n }\n console.debug(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(css_urls, js_urls, callback) {\n if (css_urls == null) css_urls = [];\n if (js_urls == null) js_urls = [];\n\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n function on_load() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n run_callbacks()\n }\n }\n\n function on_error(url) {\n console.error(\"failed to load \" + url);\n }\n\n for (let i = 0; i < css_urls.length; i++) {\n const url = css_urls[i];\n const element = document.createElement(\"link\");\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.rel = \"stylesheet\";\n element.type = \"text/css\";\n element.href = url;\n console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n document.body.appendChild(element);\n }\n\n for (let i = 0; i < js_urls.length; i++) {\n const url = js_urls[i];\n const element = document.createElement('script');\n element.onload = on_load;\n element.onerror = on_error.bind(null, url);\n element.async = false;\n element.src = url;\n console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.head.appendChild(element);\n }\n };\n\n function inject_raw_css(css) {\n const element = document.createElement(\"style\");\n element.appendChild(document.createTextNode(css));\n document.body.appendChild(element);\n }\n\n const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.3.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-2.4.3.min.js\"];\n const css_urls = [];\n\n const inline_js = [ function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\nfunction(Bokeh) {\n }\n ];\n\n function run_inline_js() {\n if (root.Bokeh !== undefined || force === true) {\n for (let i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }\nif (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n const cell = $(document.getElementById(\"1004\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n }\n\n if (root._bokeh_is_loading === 0) {\n console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(css_urls, js_urls, function() {\n console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));", "application/vnd.bokehjs_load.v0+json": "" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "output_notebook()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "edges_path = Path(r'C:\\Users\\KSpicer\\Documents\\GitHub\\solo_projects\\weird_fiction_visualizations\\datasets\\fake_data_gephi_file.csv')\n", "edges_df = pd.read_csv(edges_path)\n", "edges_df = edges_df.dropna()\n", "edges_df['target'] = edges_df['target'].astype('int')\n", "\n", "G = nx.from_pandas_edgelist(edges_df, source='source', target='target', edge_attr='Semester and Year')" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": "(function(root) {\n function embed_document(root) {\n const docs_json = {\"27612f17-fd0b-4e24-9f77-6383f3c0fab8\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1234\"}],\"center\":[{\"id\":\"1237\"},{\"id\":\"1241\"}],\"left\":[{\"id\":\"1238\"}],\"renderers\":[{\"id\":\"1253\"}],\"title\":{\"id\":\"1226\"},\"toolbar\":{\"id\":\"1247\"},\"x_range\":{\"id\":\"1223\"},\"x_scale\":{\"id\":\"1230\"},\"y_range\":{\"id\":\"1224\"},\"y_scale\":{\"id\":\"1232\"}},\"id\":\"1225\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1230\",\"type\":\"LinearScale\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1255\"},\"glyph\":{\"id\":\"1263\"},\"group\":null,\"hover_glyph\":null,\"view\":{\"id\":\"1257\"}},\"id\":\"1256\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"1259\"},\"glyph\":{\"id\":\"1268\"},\"group\":null,\"hover_glyph\":null,\"view\":{\"id\":\"1261\"}},\"id\":\"1260\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"1238\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"1241\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1303\",\"type\":\"NodesOnly\"},{\"attributes\":{},\"id\":\"1235\",\"type\":\"BasicTicker\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Weird Fiction Discussion Board Visualization\"},\"id\":\"1226\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1243\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1239\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1312\",\"type\":\"Selection\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"Poster\",\"@index\"]]},\"id\":\"1246\",\"type\":\"HoverTool\"},{\"attributes\":{\"graph_layout\":{\"0\":[-14.308164001890969,15.728298486248177],\"1\":[25.671028252166007,-0.7604558346269482],\"10\":[-17.142336018184785,31.760631852380698],\"102\":[7.764572643942281,11.346954781527524],\"13\":[31.358951553939256,32.51162048822024],\"14\":[2.4552804180643517,-39.364454611761104],\"16\":[-31.203313989127057,8.263506665308253],\"18\":[-15.450919218091533,-39.732589826639156],\"19\":[-21.33411319124323,-7.397331618164146],\"20\":[25.826374621018438,-17.006437966957623],\"21\":[23.793985463983287,-12.031994523114477],\"26\":[15.1011052423578,-9.941877073962718],\"27\":[27.044307137971018,9.335394862173477],\"28\":[-25.668692810109807,-44.93606262942266],\"29\":[12.654355448169548,32.99071420459604],\"30\":[22.19941811615253,20.65770778534257],\"31\":[-1.7205002072771833,31.6943406066694],\"33\":[-1.510694214576137,-21.251046609511103],\"34\":[-1.9041255919890356,-0.6694858497270877],\"38\":[16.556648422941482,-25.118406716152215],\"39\":[36.404200565852086,24.233630645753347],\"4\":[8.523142310741004,12.584871692246448],\"40\":[6.148229844308517,42.58505739049767],\"41\":[-7.619107505088261,0.8075193622460979],\"42\":[37.21132265759899,-1.6110317054314602],\"43\":[30.289955887751134,11.615031898744997],\"44\":[-42.33782843848115,-3.5149865741244457],\"45\":[-20.263697594399346,15.137121194084083],\"46\":[25.36912586333843,24.957097873081885],\"47\":[-12.89791692733924,-50.0],\"48\":[32.28771635934071,-8.940023386753467],\"51\":[-2.6763451687251028,41.788549722051975],\"53\":[5.225223426499293,-7.1215276368575955],\"55\":[-42.50552483679347,-26.140726050889548],\"57\":[-2.4672643440509225,29.937695991771502],\"59\":[-8.899931703857604,-32.07489639265545],\"60\":[-30.75110511527567,-28.790188728186465],\"63\":[-29.008942205345104,-18.009207030957892],\"64\":[-21.386692994763855,24.01467381809204],\"65\":[9.902672630910136,16.161362028801335],\"66\":[-36.013366901701986,-14.444477716017296],\"69\":[-35.15553692568565,-38.01834523611675],\"70\":[-45.60465909396413,-13.622365450468045],\"71\":[23.806053849875056,37.639060170601155],\"72\":[15.62105781991007,42.10712644702321],\"73\":[16.808076002149363,-39.66303192988563],\"76\":[39.72495465990305,6.501442425616693],\"78\":[-14.524351328081492,8.387470290896008],\"82\":[9.797078971034944,29.293826450113684],\"83\":[-11.010759623648399,37.53862146456724],\"84\":[17.76512695956732,-6.694241069162733],\"86\":[-14.702586370810304,28.84630498097763],\"87\":[-33.926647867989395,-3.725413601580835],\"89\":[6.222638250170006,-31.806942106564136],\"9\":[39.53483237173442,15.944003720352915],\"91\":[-10.99878486955121,-19.09718105838947],\"92\":[-19.46014827196282,-25.768852593503212],\"93\":[-10.970693514698896,22.118691651571908],\"94\":[-1.5176615280786698,-49.845282238433775],\"95\":[10.43753167535119,-46.602657510497764],\"96\":[-26.772319758973772,19.752101565972225],\"99\":[30.209764705014514,-2.5389092410152587]}},\"id\":\"1262\",\"type\":\"StaticLayoutProvider\"},{\"attributes\":{},\"id\":\"1245\",\"type\":\"ResetTool\"},{\"attributes\":{\"source\":{\"id\":\"1259\"}},\"id\":\"1261\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1311\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1314\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"1255\"}},\"id\":\"1257\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1304\",\"type\":\"NodesOnly\"},{\"attributes\":{\"data\":{\"Semester and Year\":[\"Fall 2019\",\"Spring 2022\",\"Spring 2022\",\"Spring 2021\",\"Spring 2022\",\"Fall 2020\",\"Spring 2021\",\"Spring 2020\",\"Spring 2020\",\"Spring 2020\",\"Fall 2019\",\"Fall 2020\",\"Fall 2022\",\"Fall 2021\",\"Fall 2019\",\"Spring 2020\",\"Spring 2022\",\"Spring 2019\",\"Fall 2020\",\"Spring 2019\",\"Spring 2019\",\"Spring 2020\",\"Fall 2022\",\"Fall 2022\",\"Spring 2021\",\"Spring 2022\",\"Fall 2022\",\"Fall 2020\",\"Fall 2021\",\"Spring 2022\",\"Fall 2019\",\"Fall 2020\",\"Spring 2022\",\"Spring 2022\",\"Spring 2021\",\"Spring 2022\",\"Fall 2021\",\"Fall 2021\",\"Spring 2022\",\"Fall 2020\",\"Spring 2019\",\"Fall 2019\",\"Fall 2019\",\"Fall 2021\",\"Spring 2021\",\"Spring 2020\",\"Fall 2020\",\"Spring 2021\",\"Spring 2022\",\"Spring 2020\",\"Spring 2019\",\"Spring 2021\",\"Spring 2019\",\"Fall 2019\",\"Fall 2019\",\"Fall 2021\",\"Fall 2020\",\"Spring 2021\",\"Fall 2020\",\"Spring 2022\",\"Fall 2022\",\"Fall 2019\",\"Spring 2022\",\"Fall 2020\",\"Spring 2019\",\"Fall 2019\",\"Fall 2019\",\"Fall 2021\",\"Spring 2021\",\"Spring 2020\",\"Fall 2020\",\"Spring 2021\",\"Spring 2022\",\"Spring 2020\",\"Spring 2019\",\"Spring 2021\",\"Spring 2019\",\"Fall 2019\",\"Fall 2019\",\"Fall 2021\",\"Fall 2020\",\"Spring 2021\",\"Fall 2020\",\"Spring 2022\",\"Fall 2022\",\"Fall 2019\"],\"end\":[34,65,84,34,27,57,86,0,96,16,19,87,63,92,59,89,33,38,20,99,30,91,4,102,73,44,70,66,55,69,94,47,18,60,28,14,4,102,76,13,71,72,40,29,51,31,10,93,83,64,45,78,41,53,26,21,48,42,9,1,43,39,76,13,71,72,40,29,51,31,10,93,83,64,45,78,41,53,26,21,48,42,9,1,43,39],\"start\":[82,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,95,91,91,91,91,91,91,91,91,91,91,91,91,91,91,46,46,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102]},\"selected\":{\"id\":\"1314\"},\"selection_policy\":{\"id\":\"1313\"}},\"id\":\"1259\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1306\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1307\",\"type\":\"AllLabels\"},{\"attributes\":{\"data\":{\"index\":[82,34,95,91,46,4,102,65,76,73,84,13,44,71,72,40,70,27,29,51,31,10,57,93,66,86,0,96,16,55,83,69,19,64,87,94,63,92,45,78,59,47,41,89,18,53,26,21,48,42,60,33,9,28,14,38,1,20,99,43,39,30]},\"selected\":{\"id\":\"1312\"},\"selection_policy\":{\"id\":\"1311\"}},\"id\":\"1255\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1309\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"active_scroll\":{\"id\":\"1243\"},\"tools\":[{\"id\":\"1242\"},{\"id\":\"1243\"},{\"id\":\"1244\"},{\"id\":\"1245\"},{\"id\":\"1246\"}]},\"id\":\"1247\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1244\",\"type\":\"SaveTool\"},{\"attributes\":{\"axis\":{\"id\":\"1234\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"1237\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1310\",\"type\":\"AllLabels\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1309\"},\"group\":null,\"major_label_policy\":{\"id\":\"1310\"},\"ticker\":{\"id\":\"1235\"}},\"id\":\"1234\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"skyblue\"},\"size\":{\"value\":15}},\"id\":\"1263\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"1313\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"1306\"},\"group\":null,\"major_label_policy\":{\"id\":\"1307\"},\"ticker\":{\"id\":\"1239\"}},\"id\":\"1238\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1232\",\"type\":\"LinearScale\"},{\"attributes\":{\"end\":50,\"start\":-50},\"id\":\"1223\",\"type\":\"Range1d\"},{\"attributes\":{\"line_alpha\":{\"value\":0.5}},\"id\":\"1268\",\"type\":\"MultiLine\"},{\"attributes\":{\"end\":50,\"start\":-50},\"id\":\"1224\",\"type\":\"Range1d\"},{\"attributes\":{\"coordinates\":null,\"edge_renderer\":{\"id\":\"1260\"},\"group\":null,\"inspection_policy\":{\"id\":\"1304\"},\"layout_provider\":{\"id\":\"1262\"},\"node_renderer\":{\"id\":\"1256\"},\"selection_policy\":{\"id\":\"1303\"}},\"id\":\"1253\",\"type\":\"GraphRenderer\"},{\"attributes\":{},\"id\":\"1242\",\"type\":\"PanTool\"}],\"root_ids\":[\"1225\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.3\"}};\n const render_items = [{\"docid\":\"27612f17-fd0b-4e24-9f77-6383f3c0fab8\",\"root_ids\":[\"1225\"],\"roots\":{\"1225\":\"2036ab9b-d0ae-41a2-9c33-35a3c2a56b49\"}}];\n root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n }\n if (root.Bokeh !== undefined) {\n embed_document(root);\n } else {\n let attempts = 0;\n const timer = setInterval(function(root) {\n if (root.Bokeh !== undefined) {\n clearInterval(timer);\n embed_document(root);\n } else {\n attempts++;\n if (attempts > 100) {\n clearInterval(timer);\n console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n }\n }\n }, 10, root)\n }\n})(window);", "application/vnd.bokehjs_exec.v0+json": "" }, "metadata": { "application/vnd.bokehjs_exec.v0+json": { "id": "1225" } }, "output_type": "display_data" } ], "source": [ "title = 'Weird Fiction Discussion Board Visualization'\n", "\n", "HOVER_TOOLTIPS = [('Poster', '@index')]\n", "\n", "plot = figure(tooltips=HOVER_TOOLTIPS,\n", " tools='pan, wheel_zoom, save, reset', active_scroll='wheel_zoom',\n", " x_range = Range1d(-50, 50), y_range = Range1d(-50, 50), title=title)\n", "\n", "network_graph = from_networkx(G, nx.kamada_kawai_layout, scale=50, center=(0,0))\n", "\n", "network_graph.node_renderer.glyph = Circle(size=15, fill_color='skyblue')\n", "\n", "network_graph.edge_renderer.glyph = MultiLine(line_alpha=0.5, line_width=1)\n", "\n", "plot.renderers.append(network_graph)\n", "show(plot)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": "(function(root) {\n function embed_document(root) {\n const docs_json = {\"3dbd01dc-ae89-477a-aaee-4e30b36a71a0\":{\"defs\":[],\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3231\"}],\"center\":[{\"id\":\"3234\"},{\"id\":\"3238\"}],\"left\":[{\"id\":\"3235\"}],\"renderers\":[{\"id\":\"3250\"}],\"title\":{\"id\":\"3223\"},\"toolbar\":{\"id\":\"3244\"},\"x_range\":{\"id\":\"3220\"},\"x_scale\":{\"id\":\"3227\"},\"y_range\":{\"id\":\"3221\"},\"y_scale\":{\"id\":\"3229\"}},\"id\":\"3222\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"3456\",\"type\":\"NodesOnly\"},{\"attributes\":{},\"id\":\"3240\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"3242\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"Semester and Year\":[\"Fall 2019\",\"Spring 2022\",\"Spring 2022\",\"Spring 2021\",\"Spring 2022\",\"Fall 2020\",\"Spring 2021\",\"Spring 2020\",\"Spring 2020\",\"Spring 2020\",\"Fall 2019\",\"Fall 2020\",\"Fall 2022\",\"Fall 2021\",\"Fall 2019\",\"Spring 2020\",\"Spring 2022\",\"Spring 2019\",\"Fall 2020\",\"Spring 2019\",\"Spring 2019\",\"Spring 2020\",\"Fall 2022\",\"Fall 2022\",\"Spring 2021\",\"Spring 2022\",\"Fall 2022\",\"Fall 2020\",\"Fall 2021\",\"Spring 2022\",\"Fall 2019\",\"Fall 2020\",\"Spring 2022\",\"Spring 2022\",\"Spring 2021\",\"Spring 2022\",\"Fall 2021\",\"Fall 2021\",\"Spring 2022\",\"Fall 2020\",\"Spring 2019\",\"Fall 2019\",\"Fall 2019\",\"Fall 2021\",\"Spring 2021\",\"Spring 2020\",\"Fall 2020\",\"Spring 2021\",\"Spring 2022\",\"Spring 2020\",\"Spring 2019\",\"Spring 2021\",\"Spring 2019\",\"Fall 2019\",\"Fall 2019\",\"Fall 2021\",\"Fall 2020\",\"Spring 2021\",\"Fall 2020\",\"Spring 2022\",\"Fall 2022\",\"Fall 2019\",\"Spring 2022\",\"Fall 2020\",\"Spring 2019\",\"Fall 2019\",\"Fall 2019\",\"Fall 2021\",\"Spring 2021\",\"Spring 2020\",\"Fall 2020\",\"Spring 2021\",\"Spring 2022\",\"Spring 2020\",\"Spring 2019\",\"Spring 2021\",\"Spring 2019\",\"Fall 2019\",\"Fall 2019\",\"Fall 2021\",\"Fall 2020\",\"Spring 2021\",\"Fall 2020\",\"Spring 2022\",\"Fall 2022\",\"Fall 2019\"],\"end\":[34,65,84,34,27,57,86,0,96,16,19,87,63,92,59,89,33,38,20,99,30,91,4,102,73,44,70,66,55,69,94,47,18,60,28,14,4,102,76,13,71,72,40,29,51,31,10,93,83,64,45,78,41,53,26,21,48,42,9,1,43,39,76,13,71,72,40,29,51,31,10,93,83,64,45,78,41,53,26,21,48,42,9,1,43,39],\"start\":[82,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,34,95,91,91,91,91,91,91,91,91,91,91,91,91,91,91,46,46,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102,102]},\"selected\":{\"id\":\"3467\"},\"selection_policy\":{\"id\":\"3466\"}},\"id\":\"3256\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"Poster\",\"@index\"],[\"Degree\",\"@degree\"]]},\"id\":\"3243\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"3239\",\"type\":\"PanTool\"},{\"attributes\":{\"coordinates\":null,\"group\":null,\"text\":\"Weird Fiction Discussion Board Visualization\"},\"id\":\"3223\",\"type\":\"Title\"},{\"attributes\":{\"axis\":{\"id\":\"3231\"},\"coordinates\":null,\"group\":null,\"ticker\":null},\"id\":\"3234\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"3467\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"3232\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3466\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"3460\",\"type\":\"AllLabels\"},{\"attributes\":{},\"id\":\"3457\",\"type\":\"NodesOnly\"},{\"attributes\":{\"source\":{\"id\":\"3252\"}},\"id\":\"3254\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_color\":{\"field\":\"adjusted_node_size\",\"transform\":{\"id\":\"3268\"}},\"size\":{\"field\":\"adjusted_node_size\"}},\"id\":\"3269\",\"type\":\"Circle\"},{\"attributes\":{},\"id\":\"3462\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3463\",\"type\":\"AllLabels\"},{\"attributes\":{\"graph_layout\":{\"0\":[-43.717327477462845,24.265101633379196],\"1\":[41.03817345973445,-28.56340982902964],\"10\":[-26.4482049204875,42.432209884881004],\"102\":[41.03817345973445,28.563410114238906],\"13\":[22.019706737080185,44.89022794317689],\"14\":[34.44834355464203,-36.23964167077253],\"16\":[-47.7069613852032,14.968155429290313],\"18\":[-12.532618484047033,-48.40385887373294],\"19\":[-49.74346433740797,-5.058421784241451],\"20\":[43.71733071005345,-24.265095387705472],\"21\":[2.5324478080698793,-49.9358263905807],\"26\":[-2.5324464381244183,-49.9358263905807],\"27\":[-7.571387145668372,49.423417466878],\"28\":[30.605295349427866,-39.538788553087116],\"29\":[-12.532625934627612,48.40385617870998],\"30\":[49.74346756999858,-5.05840874572544],\"31\":[-22.019707974837928,44.89022496294466],\"33\":[22.01970226673184,-44.89023063819985],\"34\":[49.74346756999858,5.058416481515282],\"38\":[37.937906414907786,-32.568624390874966],\"39\":[48.976498844822274,-10.064919869980548],\"4\":[43.71733071005345,24.265098653146964],\"40\":[2.532456935031088,49.93582667578997],\"41\":[-22.01970201437347,-44.89023063819985],\"42\":[12.532618736405405,-48.40385887373294],\"43\":[47.70696461779381,-14.968150673732705],\"44\":[17.36526497493461,46.88760640664982],\"45\":[-37.9379061625494,-32.568624390874966],\"46\":[45.94789148399598,19.717793259482548],\"47\":[-26.448195979790807,-42.4322155601362],\"48\":[7.571379947446169,-49.42341718166873],\"51\":[-17.365263232460123,46.88760640664982],\"53\":[-7.571378204971679,-49.42341718166873],\"55\":[-48.97649859246389,10.064924625538158],\"57\":[-30.60530403776618,39.53878287783192],\"59\":[-30.60529509706949,-39.538788553087116],\"60\":[17.365256034237916,-46.887609101672794],\"63\":[-43.71733045769508,-24.265095387705472],\"64\":[-48.97649859246389,-10.064921360096664],\"65\":[37.937906414907786,32.568624676084234],\"66\":[-37.93790318231717,32.568627656316465],\"69\":[-49.999999747641624,-4.2285341859571185e-06],\"70\":[-2.53246115302106,49.93582667578997],\"71\":[12.5326276771021,48.40385617870998],\"72\":[7.571388888142863,49.423417466878],\"73\":[30.605298329660098,39.538785858064145],\"76\":[34.44834355464203,36.239641955981796],\"78\":[-34.44834330228365,-36.23964167077253],\"82\":[50.0,1.4260463168573962e-07],\"83\":[-49.7434673176402,5.0584131287540215],\"84\":[26.448199212381414,42.432212865113236],\"86\":[-41.038170227143844,28.56341607470337],\"87\":[-47.70696436543543,-14.96815216384882],\"89\":[-17.365255781879544,-46.887609101672794],\"9\":[26.448196232149183,-42.4322155601362],\"91\":[47.70696163756158,14.968155429290313],\"92\":[-41.038173207376076,-28.56340982902964],\"93\":[-34.44834926274811,36.23963599551733],\"94\":[-45.9478912316376,-19.717789994041055],\"95\":[48.97649586459004,10.064926115654274],\"96\":[-45.9478912316376,19.717793259482548],\"99\":[45.94789148399598,-19.71778850392494]}},\"id\":\"3259\",\"type\":\"StaticLayoutProvider\"},{\"attributes\":{\"source\":{\"id\":\"3256\"}},\"id\":\"3258\",\"type\":\"CDSView\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"3256\"},\"glyph\":{\"id\":\"3274\"},\"group\":null,\"hover_glyph\":null,\"view\":{\"id\":\"3258\"}},\"id\":\"3257\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"coordinates\":null,\"edge_renderer\":{\"id\":\"3257\"},\"group\":null,\"inspection_policy\":{\"id\":\"3457\"},\"layout_provider\":{\"id\":\"3259\"},\"node_renderer\":{\"id\":\"3253\"},\"selection_policy\":{\"id\":\"3456\"}},\"id\":\"3250\",\"type\":\"GraphRenderer\"},{\"attributes\":{\"end\":50,\"start\":-50},\"id\":\"3220\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"3459\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3464\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"high\":31,\"low\":6,\"palette\":[\"#8c2d04\",\"#d94801\",\"#f16913\",\"#fd8d3c\",\"#fdae6b\",\"#fdd0a2\",\"#fee6ce\",\"#fff5eb\"]},\"id\":\"3268\",\"type\":\"LinearColorMapper\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3462\"},\"group\":null,\"major_label_policy\":{\"id\":\"3463\"},\"ticker\":{\"id\":\"3232\"}},\"id\":\"3231\",\"type\":\"LinearAxis\"},{\"attributes\":{\"line_alpha\":{\"value\":0.5}},\"id\":\"3274\",\"type\":\"MultiLine\"},{\"attributes\":{\"end\":50,\"start\":-50},\"id\":\"3221\",\"type\":\"Range1d\"},{\"attributes\":{},\"id\":\"3465\",\"type\":\"Selection\"},{\"attributes\":{\"coordinates\":null,\"data_source\":{\"id\":\"3252\"},\"glyph\":{\"id\":\"3269\"},\"group\":null,\"hover_glyph\":null,\"view\":{\"id\":\"3254\"}},\"id\":\"3253\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"3241\",\"type\":\"SaveTool\"},{\"attributes\":{\"coordinates\":null,\"formatter\":{\"id\":\"3459\"},\"group\":null,\"major_label_policy\":{\"id\":\"3460\"},\"ticker\":{\"id\":\"3236\"}},\"id\":\"3235\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"3229\",\"type\":\"LinearScale\"},{\"attributes\":{\"data\":{\"adjusted_node_size\":[6,27,6,20,7,31,31,6,7,6,6,7,6,7,7,7,6,6,7,7,7,7,6,7,6,6,6,6,6,6,7,6,6,7,6,6,6,6,7,7,6,6,7,6,6,7,7,7,7,7,6,6,7,6,6,6,7,6,6,7,7,6],\"degree\":[1,22,1,15,2,26,26,1,2,1,1,2,1,2,2,2,1,1,2,2,2,2,1,2,1,1,1,1,1,1,2,1,1,2,1,1,1,1,2,2,1,1,2,1,1,2,2,2,2,2,1,1,2,1,1,1,2,1,1,2,2,1],\"index\":[82,34,95,91,46,4,102,65,76,73,84,13,44,71,72,40,70,27,29,51,31,10,57,93,66,86,0,96,16,55,83,69,19,64,87,94,63,92,45,78,59,47,41,89,18,53,26,21,48,42,60,33,9,28,14,38,1,20,99,43,39,30]},\"selected\":{\"id\":\"3465\"},\"selection_policy\":{\"id\":\"3464\"}},\"id\":\"3252\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"3227\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"3235\"},\"coordinates\":null,\"dimension\":1,\"group\":null,\"ticker\":null},\"id\":\"3238\",\"type\":\"Grid\"},{\"attributes\":{\"active_scroll\":{\"id\":\"3240\"},\"tools\":[{\"id\":\"3239\"},{\"id\":\"3240\"},{\"id\":\"3241\"},{\"id\":\"3242\"},{\"id\":\"3243\"}]},\"id\":\"3244\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"3236\",\"type\":\"BasicTicker\"}],\"root_ids\":[\"3222\"]},\"title\":\"Bokeh Application\",\"version\":\"2.4.3\"}};\n const render_items = [{\"docid\":\"3dbd01dc-ae89-477a-aaee-4e30b36a71a0\",\"root_ids\":[\"3222\"],\"roots\":{\"3222\":\"2f4100a7-dcf2-4559-be6d-f383562dd3d4\"}}];\n root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n }\n if (root.Bokeh !== undefined) {\n embed_document(root);\n } else {\n let attempts = 0;\n const timer = setInterval(function(root) {\n if (root.Bokeh !== undefined) {\n clearInterval(timer);\n embed_document(root);\n } else {\n attempts++;\n if (attempts > 100) {\n clearInterval(timer);\n console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n }\n }\n }, 10, root)\n }\n})(window);", "application/vnd.bokehjs_exec.v0+json": "" }, "metadata": { "application/vnd.bokehjs_exec.v0+json": { "id": "3222" } }, "output_type": "display_data" } ], "source": [ "degrees = dict(nx.degree(G))\n", "nx.set_node_attributes(G, name='degree', values=degrees)\n", "number_to_adjust_by = 5\n", "adjusted_node_size = dict([(node, degree+number_to_adjust_by) for node, degree in nx.degree(G)])\n", "nx.set_node_attributes(G, name='adjusted_node_size', values=adjusted_node_size)\n", "\n", "size_by_this_attribute = 'adjusted_node_size'\n", "color_by_this_attribute = 'adjusted_node_size'\n", "\n", "color_palette = Oranges8\n", "\n", "HOVER_TOOLTIPS_1 = [('Poster', '@index'), ('Degree', '@degree')]\n", "plot_1 = figure(tooltips=HOVER_TOOLTIPS_1,\n", " tools='pan, wheel_zoom, save, reset', active_scroll='wheel_zoom',\n", " x_range = Range1d(-50, 50), y_range = Range1d(-50, 50), title=title)\n", "\n", "network_graph = from_networkx(G, nx.circular_layout, scale=50, center=(0,0))\n", "minimum_value_color = min(network_graph.node_renderer.data_source.data[color_by_this_attribute])\n", "maximum_value_color = max(network_graph.node_renderer.data_source.data[color_by_this_attribute])\n", "network_graph.node_renderer.glyph = Circle(size=size_by_this_attribute, fill_color=linear_cmap(color_by_this_attribute, color_palette, minimum_value_color, maximum_value_color))\n", "\n", "network_graph.edge_renderer.glyph = MultiLine(line_alpha=0.5, line_width=1)\n", "\n", "plot_1.renderers.append(network_graph)\n", "\n", "show(plot_1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.9.12 ('victorian_authorship_env')", "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.12" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "ef5d861bb1be136369da2a14d97f47e042662aed23f513481be9d838db3326bb" } } }, "nbformat": 4, "nbformat_minor": 2 }