Package for easy visualisation of trees in Python
Project description
Easy Tree Visualization Library
The goal of this mini-project is to provide an easy, customizable way to create visualizations of tree structures, without use of networkx or similar.
What this library is
A way to parse a tree in adjacency dictionary, or list format and visualize it with a .svg file.
It supports various objects as node labels, with easily overridable way to include any object data representable as string as node label. This was done mainly with allowing easy visualization of MCTS search trees in mind. It also allows easy sorting of the nodes, by id, it's properties or object's properties. Id can also be an object, e.g. MCTS State custom timestamp class.
What it is not
This is not a library for storing, modifying, or parsing trees -- let alone graphs.
Usage
Example use of the library:
tree_data = {
"A": ["B", "C", "G"],
"B": ["D", "E"],
"C": ["F"],
"D": [], "E": [], "F": [],
"G": ["H"],
"H": ["I"],
"I": ["J"],
"J": ["K", "L"],
"K": [], "L": []
}
tree = Tree.from_dict(tree_data)
draw_tree(tree, "tree.svg")
Result:
Please visit examples/ directory for a few more examples, including customization, node ordering and visualizing different objects.
Customization
Available parameters include:
NODE_RADIUS
FONT_SIZE
EDGE_STROKE - color of lines between nodes
EDGE_STROKE_WIDTH - width of line between nodes
FILL_NODE - node fill color, per svgwrite.Drawing
STROKE_NODE - color of node border
STROKE_NODE_WIDTH - width of node border
X_SPACING - minimum spacing between nodes in the same row
Y_SPACING - minimum spacing between nodes in different rows
MARGIN - margin around entire tree, as the image is cut to width+margin by height+margin
TEXT_OFFSET - offset from middle of the node
Performance
While not specifically optimized for performance, the library is capable of handling large trees (e.g., >5000 nodes) in a few seconds.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easytreevis-1.0.0.tar.gz.
File metadata
- Download URL: easytreevis-1.0.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f765ed119768a61bb4b7352ce2284f976304777fcc433617036006d5f0027faf
|
|
| MD5 |
99e3d7114a7b070cc057504a3573d0fe
|
|
| BLAKE2b-256 |
770a008676b1d85ae6bd9985699e70984dd39a39af147e79348385118de5a4de
|
File details
Details for the file easytreevis-1.0.0-py3-none-any.whl.
File metadata
- Download URL: easytreevis-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2134a44726819e60df36d81cf33b01e54b5856796c931ce3a089ef7e4181013e
|
|
| MD5 |
5c783adfe6aa036e14552550e2cc50cc
|
|
| BLAKE2b-256 |
1dabd63acf2b25f146775bf2a96bc1e459e2e1a062a08ceda1af23a9204f86c0
|