PyBEL-Jupyter

A PyBEL extension for Jupyter notebooks.

Installation

pybel_jupyter can be installed easily from PyPI with the following code in your favorite terminal:

$ pip install pybel-jupyter

or from the latest code on GitHub with:

$ pip install git+https://github.com/pybel/pybel-jupyter.git

Getting Started

Inside a Jupyter notebook, run the following code at the end of the cell to get an interactive visualization:

>>> from pybel.examples import sialic_acid_graph
>>> from pybel_jupyter import to_jupyter
>>> to_jupyter(sialic_acid_graph)
pybel_jupyter.to_html(graph, color_map=None)[source]

Create an HTML visualization for the given JSON representation of a BEL graph.

Parameters
  • graph (BELGraph) – A BEL graph

  • color_map (Optional[Mapping[str, str]]) – A dictionary from PyBEL internal node functions to CSS color strings like #FFEE00. Defaults to default_color_map

Return type

str

Returns

HTML string representing the graph

pybel_jupyter.to_html_file(graph, file, color_map=None)[source]

Write the HTML visualization to a file or file-like.

Parameters
  • graph (BELGraph) – A BEL graph

  • color_map (Optional[Mapping[str, str]]) – A dictionary from PyBEL internal node functions to CSS color strings like #FFEE00. Defaults to default_color_map

  • file (file) – A writable file or file-like or file path

Return type

None

pybel_jupyter.to_jupyter(graph, width=1000, height=650, color_map=None)[source]

Display a BEL graph inline in a Jupyter notebook.

To use successfully, make run as the last statement in a cell inside a Jupyter notebook.

Parameters
  • graph (BELGraph) – A BEL graph

  • width (int) – The width of the visualization window to render

  • height (int) – The height of the visualization window to render

  • color_map (Optional[Mapping[str, str]]) – A dictionary from PyBEL internal node functions to CSS color strings like #FFEE00. Defaults to default_color_map

Returns

An IPython notebook Javascript object

Return type

IPython.display.Javascript

pybel_jupyter.to_jupyter_str(graph, width=1000, height=650, color_map=None)[source]

Return the string to be javascript-ified by the Jupyter notebook function IPython.display.Javascript.

Parameters
  • graph (BELGraph) – A BEL graph

  • width (int) – The width of the visualization window to render

  • height (int) – The height of the visualization window to render

  • color_map (Optional[Mapping[str, str]]) – A dictionary from PyBEL internal node functions to CSS color strings like #FFEE00. Defaults to default_color_map

Return type

str

Returns

The javascript string to turn into magic

Indices and tables