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 graphette
python -m graphette.  # 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.1.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.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: graphette-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 50b528058666d117aee07526aa68eeec8351348c2e2a172e6361f328f169de9d
MD5 423898e79eb0413111fbbd7294238cab
BLAKE2b-256 77d37e7425a433841332243bd6340411242816ceb9de792b14df36c99c8413a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: graphette-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9da926dc605e0efa07f6793fd55d07aff9e89845c4059201c328176908690805
MD5 6534502a4405b1c390fe989d3edc10a8
BLAKE2b-256 4c87f5e5c0cf9a399cbbbdcbda0f9203d82a7e493b51a0d85e3f8aa6aceba14f

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