Skip to content

Latest commit

 

History

History
89 lines (57 loc) · 2.36 KB

quickstart.rst

File metadata and controls

89 lines (57 loc) · 2.36 KB

Quickstart

nxv renders NetworkX graphs using GraphViz.

Using nxv inside of Jupyter

Start by importing networkx and nxv.

import networkx as nx
import nxv

Define a simple NetworkX graph.

.. literalinclude:: ../src/docs.py
   :start-after: BEGIN EXAMPLE
   :end-before: END EXAMPLE
   :dedent: 4
   :pyobject: quickstart_graph

Render the graph with GraphViz using the :func:`~nxv.render` function.

nxv.render(graph)

Use a :class:`~nxv.Style` to specify how to style the graph using GraphViz.

.. literalinclude:: ../src/docs.py
   :start-after: BEGIN EXAMPLE
   :end-before: END EXAMPLE
   :dedent: 4
   :pyobject: quickstart_graph_style

See the GraphViz attributes documentation for information on what attributes are available to use.

Render the graph with the :class:`~nxv.Style` by passing it to the :func:`~nxv.render` function.

nxv.render(graph, style)

The :class:`~nxv.Style` parameters can be functions that map the parts of a graph to different styles.

.. literalinclude:: ../src/docs.py
   :start-after: BEGIN EXAMPLE
   :end-before: END EXAMPLE
   :dedent: 4
   :pyobject: quickstart_graph_functional_style

nxv.render(graph, style)

Using nxv outside of Jupyter

Outside of Jupyter, the format parameter of the :func:`~nxv.render` function is required. When the format parameter is provided, the behavior of the :func:`~nxv.render` function is to return the :class:`bytes` of the result in the specified format.

data = nxv.render(graph, style, format="svg")
with open("graph.svg", "wb") as f:
    f.write(data)