Skip to main content

Visualize Tree, Graph, and Matrix data structures with ease.

Project description

Data Structure Plot (DSPlot)

Build Status Coverage Status GitHub license

DSPlot is a tool to simply visualize tree and graph data structures by serving as a Pythonic interface to the Graphviz layout. DSPlot allows you to easily draw trees, graphs (both directed and undirected), and matrices by passing data in primitive form and directly output an image.

⬇ Installation

0. Prerequisites

  • Python 3.7 or later
  • pip
  • virtualenv

1. Install Graphviz

  • MacOS:
brew install graphviz
  • Linux:
apt-get install graphviz libgraphviz-dev

2. Install package

$ pip install dsplot

🤟 Usage

  • Binary Tree:
from dsplot.tree import BinaryTree

tree = BinaryTree(nodes=[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1])
tree.plot()

tree

  • Graph:
from dsplot.graph import Graph

graph = Graph(
    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []}, directed=True
)
graph.plot()

directed

from dsplot.graph import Graph

graph = Graph(
    {1: [2, 4], 2: [1, 3], 3: [2, 4, 5], 4: [1, 3], 5: [3, 6, 7], 6: [5], 7: [5]}, directed=False
)
graph.plot()

undirected

  • Matrix:
from dsplot.matrix import Matrix

matrix = Matrix([[1, 2, 3], [4, 5, 6], [1, 2, 6]])
matrix.plot()

matrix

  • Customization:
    You can customize the border color, shape, style, and fill color of the nodes, and the orientation (left to right - LR, top to bottom - TB) of the graph.
from dsplot.graph import Graph

graph = Graph(
    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []}, directed=True
)
graph.plot(fill_color='#aec6cf')

colored

from dsplot.tree import BinaryTree

tree = BinaryTree(nodes=[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1])
tree.plot(orientation='LR', border_color='#FFCE30', fill_color='#aec6cf')

colored

🎁 Additional features

1. Tree traversals:

from dsplot.tree import BinaryTree

tree = BinaryTree(nodes=[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1])

print(tree.preorder())
# [5, 4, 11, 7, 2, 8, 13, 4, 5, 1]

print(tree.inorder())
# [7, 11, 2, 4, 5, 13, 8, 5, 4, 1]

print(tree.postorder())
# [7, 2, 11, 4, 13, 5, 1, 4, 8, 5]

2. Graph traversals:

from dsplot.graph import Graph

graph = Graph(
    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []}, directed=True
)

print(graph.bfs())
# [0, 1, 4, 5, 3, 2]

print(graph.dfs())
# [0, 1, 3, 2, 4, 5]

📄 License

MIT

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

dsplot-0.7.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

dsplot-0.7.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file dsplot-0.7.0.tar.gz.

File metadata

  • Download URL: dsplot-0.7.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Darwin/21.4.0

File hashes

Hashes for dsplot-0.7.0.tar.gz
Algorithm Hash digest
SHA256 6053a11bf273b090bb9025357d4626e22945cbeb303760ec054a433a39650cef
MD5 0520c772f445b5c416ab2fc11b8ea675
BLAKE2b-256 39ab6a86ae39bdf0fba6228f012e321ae1fb0d369e533aa28d653b86c1309630

See more details on using hashes here.

File details

Details for the file dsplot-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: dsplot-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Darwin/21.4.0

File hashes

Hashes for dsplot-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ee97709bff5f774685a15df817df301108979fa9662da7a854e3f13fedd0cb8
MD5 34437d2969b31939292bdaa94dd721e4
BLAKE2b-256 17f43cfe24e1a64e9e5055565c96da25f69624fa661e3581ff068bf7cb72137b

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