Skip to main content

An algorithm visualization tool for jupyter notebook to show animation for vector, table, linked list, tree and graph data structures.

Project description

Algviz

Introduce

Algviz is an algorithm visualization tool for Jupyter-notebook.

Algviz can generate visualize animations for vector, table, linked list, tree and graph data structures. You can bring your code to life after insert a few algviz interfaces into code. All the animations were generated in real time, so you can easily preview the changes of the data with animation like that:

vector_swap_animation

If you come up with a good algorithm that can solve a problem, but don't know how to describe it to your friends. At this point, you can use algviz to create an intuitive animation demo to show to working process of your algorithm. The point is, you don't need to know about fundamentals of animation at all. Leave the dirty work to algviz and just focus on how to implement your algorithm.

It's useful when you try to express the working process of a complex algorithm. For example, it's hard to image in mind the whole detail of mirror binary tree algorithm. Because the algorithm including some recursive operations on a binary tree, which subtree was moved first is a headache problem. But no matter how complex the binary tree is, algviz can tell you how the algorithm works by intuitive animations.

This animation below shows one swap subtrees operation in mirror binary tree algorithm:

mirror_tree_animation

Furthermore, algviz provides some encapsulated data classes which support operations like python builtin class. For example, you can iterate on the algviz.Vector class just like Python list:

import algviz                   # Import algviz library.
viz = algviz.Visualizer()       # Create a visualizer object.
data = [1, 2, 3]
vector = viz.createVector(data) # Create a vector data object.
for num in vector:              # Iterate over all the elements in vector.
    print(num)
    viz.display()               # Refresh the animation in Jupyter-notebook.

You can modify the data multi-times, and algviz will record all the operations since last time you call the display interface. Then it will merge all the operations in one animation when you call display next time. So the only thing you need to concern is: when to call the display interface? Because some operations may override other operations and the output animation may be confusing.

These animations below shows multiple operations in one render output:

  • Two insert operations on vector. (Insert two elements "0" and "1" into vector ["a", "b", "c"].)

    vector_move_animation

  • Modify two edges on graph. (Add node7 into node5's neighbors; Remove nodes4 from node5's neighbors).

    graph_move_animation

All the animations created by algviz are SVG string format. You can export the animation frames and review it in browser or embedded it in your slides.

Installation

Step1: Install Jupyter-notebook

Algviz can only run in Jupyter-notebook. You can choose any of the following methods to install Jupyter-notebook.

Step2: Install Graphviz

Graphviz was used to generate static layout of topology graph. It's a popular open source software, you can download the program in it's official site.

Note: please remember to add graphviz into your system's environment path so that other programs can call it directly.

Step3: Install algviz

Note: algviz run on Python 3.7 or heigher version of Python.

python -m pip install --upgrade pip
pip install algviz

API Reference

All the API reference for algviz can be found on readthedocs.

Examples

There are some example in the examples folder. You can download them from github and open the notebook in your local environment.

These is the example notebooks:

Online Examples

If you are a google colab user, you can click the links below to run the notebook on your browser directly.

Unit Test

Make sure you have successfully installed algviz from PyPi and download the test codes from github.

Then call the command:

python tests/run.py

If you see the output like this:

Congratulations, everything is OK !!!

It means algviz working fine in your environment. Otherwise please report the bug.

License

Algviz use GNU general pubilc LICENSE. You can freely use it for non-commercial learning and communication, and commercial use is not allowed.

Links

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

algviz-0.1.1.tar.gz (48.4 kB view hashes)

Uploaded Source

Built Distribution

algviz-0.1.1-py3-none-any.whl (51.2 kB view hashes)

Uploaded Python 3

Supported by

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