Code Monkey home page Code Monkey logo

nx2d3's Introduction

nx2d3

Display NetworkX graphs inline in Jupyter notebooks

Installing

From the latest code on GitHub with:

$ python3 -m pip install git+https://github.com/cthoyt/nx2d3.git

Example

>>> import networkx as nx
>>> import nx2d3
>>> G = nx.petersen_graph()
>>> nx2d3.embed_networkx(G)

Note: GitHub will not render custom javascript on https://github.com/cthoyt/nx2d3/blob/master/example.ipynb. Instead, try nbviewer http://nbviewer.jupyter.org/github/cthoyt/nx2d3/blob/master/example.ipynb or viewing the notebooks in jupyter notebook locally.

nx2d3's People

Contributors

anentropic avatar cthoyt avatar

Watchers

 avatar  avatar  avatar

nx2d3's Issues

TypeError: Object of type 'int64' is not JSON serializable

When you try to render a graph derived from a numpy adjacency matrix, you get this error.

G = nx.from_numpy_matrix(mymatrix)
nx2d3.embed_networkx(G)

This can be solved by converting node IDs to strings (G = nx.relabel_nodes(G, lambda x: str(x))) but it seems like a more general solution is to handle this in the embed_networkx call, since any non-JSON-serializable ID type will fail with this error.

(Traceback suggests that this is a failure of the node_link_data(graph) call on line 99 of embed.py)

[EDIT]: This still fails even if I verify that the data are JSON-serializable with

G =  json_graph.node_link_graph(json_graph.node_link_data(G))

So this is a function of the nx2d3 library, not of the networkx JSON serializer, I believe.

More default renderings

figure out what common use cases are and make multiple defaults. possibly split into a different py file, make functions that return the strings?

Support for directed graphs

make explicitly different functions for each, possibly use a global function that checks the type and decides

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.