Skip to main content

altair-nx

Documentation Status PyPI Version PyPI Downloads Python Versions License Actions Status

Draw interactive NetworkX graphs with Altair

altair-nx offers a similar draw API to NetworkX but returns Altair Charts instead.

This allows much greater customisability, adds support for curved edges and self loops, and introduces interactivity into graph representations (e.g. node and edge property changes, and selection-based reactions), including support for graph time-lapses.

This project started as a fork of nx-altair (inactive since 2020) meant for fixing issues and merging pull requests, but after a full code-base rework (causing backward and forward incompatibility) and the implementation of new features, it became reasonable for it to be its own library.

Installation:

uv pip install altair-nx

Examples

Every function argument is explained in the documentation (and most IDEs will pull from it on hover or for auto-complete), but the simplest starting point for altair-nx is playing around with the tutorial notebook.

PS: if you draw something cool or which could be a good example of using combinations of the various features, feel free to put it in a notebook and open a pull request with it added to the examples folder (note that GitHub suppresses interactive charts, therefore copy the png renderer bit at the top of current examples).

Simple graph

import networkx as nx
import altair_nx as anx

# Generate a random graph
G = nx.fast_gnp_random_graph(n = 20, p = 0.25)

# Compute node positions
pos = nx.spring_layout(G)

# Draw the graph with altair-nx
viz = anx.draw_networkx(G, pos)

# Display it and make it interactive
viz.interactive()

Minimal customisation

Many of altair-nx's style configuration arguments (most being similar to NetworkX's) support declarative mapping to node and edge attributes (e.g. colours, shapes, and sizes). Again, see the documentation or the tutorial notebook, but here is a simple styling of the graph from above:

import numpy as np

# Add attributes to nodes and edges
for n in G.nodes(): G.nodes[n]['importance'] = np.random.randn()
for e in G.edges(): G.edges[e]['weight'] = np.random.uniform(1, 10)

# Draw the graph with altair-nx
viz = anx.draw_networkx(G, pos,
    node_colour = 'importance', node_cmap = 'viridis',
    edge_colour = 'black', edge_width = 'weight', curved_edges = True
)

# Display it and make it interactive
viz.interactive()

Leverage Altair for deeper interactivity

Make a chart depend on a selection over the graph:

Create controls to affect chart parameters:

Create a slider-driven timelapse from a sequence of NetworkX graph snapshots with anx.stitch_frames and anx.draw_networkx_timelapse. Nodes and edges can be made to appear or disappear, and their attributes can change from frame to frame.

All examples are in the tutorial notebook.

Metadata

Release files for altair-nx 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for altair-nx 2.0
File Size Uploaded Provenance Actions
altair_nx-2.0.tar.gz 4.0 MB Without provenance Details for altair_nx-2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for altair-nx 2.0
File Interpreter ABI Platform Actions
altair_nx-2.0-py3-none-any.whl Python 3 none any Details for altair_nx-2.0-py3-none-any.whl

Total release size: 4.0 MB

Release files / altair_nx-2.0.tar.gz

Download URL altair_nx-2.0.tar.gz
Size 4.0 MB
Tags Source
SHA-256 checksum
How to use checksums
50f6768989b2ff9aede4faf545c69b82b14726581130a57264e90ece1cdaf019
BLAKE2b-256 checksum
How to use checksums
2559baf0c740c8312e632afb1770c373529b837b2e18f68008c423e9ab70e8e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / altair_nx-2.0-py3-none-any.whl

Download URL altair_nx-2.0-py3-none-any.whl
Size 28.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b77c0166562ac05a2513596bfc3dbb0849b89f4beea285e10604ca11d6523c10
BLAKE2b-256 checksum
How to use checksums
e88528d6d1307701a2acc85a74488239566a484712f7798ed9cb13566a2225a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for altair-nx 2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page