Skip to main content

Step-by-step graph algorithm visualization with NetworkX and Matplotlib

Project description

Graph Algorithm Visualizer

Step-by-step graph algorithm visualization with NetworkX and Matplotlib.

BFS Example

Usage

pip install -r requirements.txt
python visualize.py  # run included BFS example

Custom Algorithms

To make a custom visualization, create a generator that yields snapshot() at each step:

from algo import snapshot, adjacency
from visualize import visualize, animate


def dfs(edges, start):
    adj = adjacency(edges)
    stack, visited, step = [start], set(), 0

    while stack:
        cur = stack.pop()
        if cur in visited: continue
        visited.add(cur)
        step += 1

        yield snapshot(step, edges=edges, event="visit",
                       state={'visited': list(visited)},
                       node_color={'orange': ('current', cur)},
                       nodes_color={'lightgreen': ('visited', visited)})

        stack.extend(n for n in adj[cur] if n not in visited)


states = dfs(edges, 'A')
visualize(states)  # interactive (← → to navigate)
animate(states, 'out.gif')  # supports all matplotlib.animation formats

Snapshot Parameters

Parameter Description
step, event Step number and label
nodes, edges Current state of the graph
state Algorithm state dict to display
node_color {color: (label, node)}
nodes_color {color: (label, node_set)}
edges_color {color: (label, edge_set)}

Requirements

matplotlib, networkx, toolz

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphette-0.1.0.tar.gz (129.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphette-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file graphette-0.1.0.tar.gz.

File metadata

  • Download URL: graphette-0.1.0.tar.gz
  • Upload date:
  • Size: 129.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for graphette-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5cddd6ba166d8c37be95cc1002642cbac747c901a584b0c07d104bcf8a31a91d
MD5 f4a08eec94c2b64c237922654236d8fe
BLAKE2b-256 3a6847adac536de08d2ad65608688774d4a0eb514d33866da72baf379f002b34

See more details on using hashes here.

File details

Details for the file graphette-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: graphette-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for graphette-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02eba03c2a84200219815b41f460f94af78cb595ef0dcb8e09dcee2271b961ad
MD5 c7ce284cac9def09ba816dd42f2a4cb2
BLAKE2b-256 790f013b2b9f4a164daf5683c97fdfed801bef3ba4f49ef7409a5c7f78c33aa2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page