{ "metadata": { "name": "", "signature": "sha256:d5b549f8fed1548363e59b74dd75395e5c306205363119c8539e8e360fdb16b7" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import networkx as nx\n", "\n", "import plotly.plotly as py\n", "from plotly.graph_objs import *" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "G=nx.random_geometric_graph(200,0.125)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "# add the edges in as disconnected lines in a single trace\n", "edge_trace = Scatter(x=[], y=[], mode='lines')\n", "for edge in G.edges():\n", " x0, y0 = G.node[edge[0]]['pos']\n", " x1, y1 = G.node[edge[1]]['pos']\n", " edge_trace['x'] += [x0, x1, None]\n", " edge_trace['y'] += [y0, y1, None]\n", "\n", "# add the nodes in as a scatter\n", "node_trace = Scatter(x=[], y=[], mode='markers', marker=Marker(size=[]))\n", "for node in G.nodes():\n", " x, y = G.node[node]['pos']\n", " node_trace['x'].append(x)\n", " node_trace['y'].append(y)\n", "\n", "# size the node points by the number of connections\n", "for node, adjacencies in enumerate(G.adjacency_list()):\n", " node_trace['marker']['size'].append(len(adjacencies))" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "# create a figure so we can customize a couple more things\n", "fig = Figure(data=Data([edge_trace, node_trace]),\n", " layout=Layout(title='random geometric graph from networkx', plot_bgcolor=\"rgb(217, 217, 217)\",\n", " showlegend=False, xaxis=XAxis(showgrid=False, zeroline=False, showticklabels=False),\n", " yaxis=YAxis(showgrid=False, zeroline=False, showticklabels=False)))\n", "\n", "# send the figure to Plotly and embed an iframe in this notebook\n", "py.iplot(fig, filename='networkx')" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "" ], "metadata": {}, "output_type": "pyout", "prompt_number": 4, "text": [ "" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }