dsplot


Namedsplot JSON
Version 0.9.0 PyPI version JSON
download
home_page
SummaryVisualize Tree, Graph, and Matrix data structures with ease.
upload_time2023-02-24 17:29:34
maintainer
docs_urlNone
authorBill
requires_python>=3.7,<4.0
licenseMIT
keywords data structure tree graph matrix plot
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Data Structure Plot (DSPlot)
[![Build Status](https://travis-ci.com/billtrn/dsplot.svg?branch=master)](https://travis-ci.com/billtrn/dsplot)
[![Coverage Status](https://coveralls.io/repos/github/billtrn/dsplot/badge.svg?branch=master)](https://coveralls.io/github/billtrn/dsplot?branch=master)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/billtrn/dsplot/blob/master/LICENSE)

DSPlot is a tool to simply visualize tree and graph data structures by serving as a Pythonic interface to the [Graphviz](https://graphviz.org/) 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
```
- Other OS(s): https://graphviz.org/download/

#### 2. Install package
```
$ pip install dsplot
```

## 🤟 Usage
- Binary Tree:
```python
from dsplot.tree import BinaryTree

tree = BinaryTree(nodes=[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1])
tree.plot()
```
![tree](https://github.com/billtrn/dsplot/blob/master/img/tree.png?raw=true)

- Graph:
```python
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](https://github.com/billtrn/dsplot/blob/master/img/directed.png?raw=true)
```python
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](https://github.com/billtrn/dsplot/blob/master/img/undirected.png?raw=true)

- Matrix:
```python
from dsplot.matrix import Matrix

matrix = Matrix([[1, 2, 3], [4, 5, 6], [1, 2, 6]])
matrix.plot()
```
![matrix](https://github.com/billtrn/dsplot/blob/master/img/matrix.png?raw=true)

- Customization: <br>
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.
```python
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](https://github.com/billtrn/dsplot/blob/master/img/color_graph.png?raw=true)
```python
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](https://github.com/billtrn/dsplot/blob/master/img/color_tree.png?raw=true)

- Edge values for Graphs: <br>
For edge values, `str` and `int` data types are supported at the moment.
```python
from dsplot.graph import Graph

graph = Graph(
    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []},
    directed=True,
    edges={'01': 1, '04': 4, '05': 5, '13': 3, '14': 4, '21': 2, '32': 3, '34': 4},
)
graph.plot()
```
![edge](https://github.com/billtrn/dsplot/blob/master/img/edge_graph.png?raw=true)
## 🎁 Additional features
### 1. Tree traversals:
```python
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:
```python
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](./LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "dsplot",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "Data Structure,Tree,Graph,Matrix,Plot",
    "author": "Bill",
    "author_email": "trantriducs@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/36/20/5db681dcb9db7f80504c3320c62c28a885446a65ba4d6671a41adcf5626e/dsplot-0.9.0.tar.gz",
    "platform": null,
    "description": "# Data Structure Plot (DSPlot)\n[![Build Status](https://travis-ci.com/billtrn/dsplot.svg?branch=master)](https://travis-ci.com/billtrn/dsplot)\n[![Coverage Status](https://coveralls.io/repos/github/billtrn/dsplot/badge.svg?branch=master)](https://coveralls.io/github/billtrn/dsplot?branch=master)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/billtrn/dsplot/blob/master/LICENSE)\n\nDSPlot is a tool to simply visualize tree and graph data structures by serving as a Pythonic interface to the [Graphviz](https://graphviz.org/) layout.\nDSPlot allows you to easily draw trees, graphs (both directed and undirected), and matrices by passing data in primitive form and directly output an image.\n\n## \u2b07 Installation\n\n#### 0. Prerequisites\n- Python 3.7 or later\n- `pip`\n- `virtualenv`\n\n#### 1. Install Graphviz\n- MacOS:\n```\nbrew install graphviz\n```\n- Linux:\n```\napt-get install graphviz libgraphviz-dev\n```\n- Other OS(s): https://graphviz.org/download/\n\n#### 2. Install package\n```\n$ pip install dsplot\n```\n\n## \ud83e\udd1f Usage\n- Binary Tree:\n```python\nfrom dsplot.tree import BinaryTree\n\ntree = BinaryTree(nodes=[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1])\ntree.plot()\n```\n![tree](https://github.com/billtrn/dsplot/blob/master/img/tree.png?raw=true)\n\n- Graph:\n```python\nfrom dsplot.graph import Graph\n\ngraph = Graph(\n    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []}, directed=True\n)\ngraph.plot()\n```\n![directed](https://github.com/billtrn/dsplot/blob/master/img/directed.png?raw=true)\n```python\nfrom dsplot.graph import Graph\n\ngraph = Graph(\n    {1: [2, 4], 2: [1, 3], 3: [2, 4, 5], 4: [1, 3], 5: [3, 6, 7], 6: [5], 7: [5]}, directed=False\n)\ngraph.plot()\n```\n![undirected](https://github.com/billtrn/dsplot/blob/master/img/undirected.png?raw=true)\n\n- Matrix:\n```python\nfrom dsplot.matrix import Matrix\n\nmatrix = Matrix([[1, 2, 3], [4, 5, 6], [1, 2, 6]])\nmatrix.plot()\n```\n![matrix](https://github.com/billtrn/dsplot/blob/master/img/matrix.png?raw=true)\n\n- Customization: <br>\nYou 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.\n```python\nfrom dsplot.graph import Graph\n\ngraph = Graph(\n    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []}, directed=True\n)\ngraph.plot(fill_color='#aec6cf')\n```\n![colored](https://github.com/billtrn/dsplot/blob/master/img/color_graph.png?raw=true)\n```python\nfrom dsplot.tree import BinaryTree\n\ntree = BinaryTree(nodes=[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1])\ntree.plot(orientation='LR', border_color='#FFCE30', fill_color='#aec6cf')\n```\n![colored](https://github.com/billtrn/dsplot/blob/master/img/color_tree.png?raw=true)\n\n- Edge values for Graphs: <br>\nFor edge values, `str` and `int` data types are supported at the moment.\n```python\nfrom dsplot.graph import Graph\n\ngraph = Graph(\n    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []},\n    directed=True,\n    edges={'01': 1, '04': 4, '05': 5, '13': 3, '14': 4, '21': 2, '32': 3, '34': 4},\n)\ngraph.plot()\n```\n![edge](https://github.com/billtrn/dsplot/blob/master/img/edge_graph.png?raw=true)\n## \ud83c\udf81 Additional features\n### 1. Tree traversals:\n```python\nfrom dsplot.tree import BinaryTree\n\ntree = BinaryTree(nodes=[5, 4, 8, 11, None, 13, 4, 7, 2, None, None, 5, 1])\n\nprint(tree.preorder())\n# [5, 4, 11, 7, 2, 8, 13, 4, 5, 1]\n\nprint(tree.inorder())\n# [7, 11, 2, 4, 5, 13, 8, 5, 4, 1]\n\nprint(tree.postorder())\n# [7, 2, 11, 4, 13, 5, 1, 4, 8, 5]\n```\n### 2. Graph traversals:\n```python\nfrom dsplot.graph import Graph\n\ngraph = Graph(\n    {0: [1, 4, 5], 1: [3, 4], 2: [1], 3: [2, 4], 4: [], 5: []}, directed=True\n)\n\nprint(graph.bfs())\n# [0, 1, 4, 5, 3, 2]\n\nprint(graph.dfs())\n# [0, 1, 3, 2, 4, 5]\n```\n## \ud83d\udcc4 License\n[MIT](./LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Visualize Tree, Graph, and Matrix data structures with ease.",
    "version": "0.9.0",
    "project_urls": null,
    "split_keywords": [
        "data structure",
        "tree",
        "graph",
        "matrix",
        "plot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9ff1495c03b0e47a8ac7ce42432a8b81a519befdd4245038a1ef65a1cb48e9b2",
                "md5": "3633a7f3ca6dfb03396b93e5556ec49d",
                "sha256": "0c7349196d53982c220d29e0c0dc2993e750730c8df12668aaf60aa249889ecf"
            },
            "downloads": -1,
            "filename": "dsplot-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3633a7f3ca6dfb03396b93e5556ec49d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 8769,
            "upload_time": "2023-02-24T17:29:33",
            "upload_time_iso_8601": "2023-02-24T17:29:33.319019Z",
            "url": "https://files.pythonhosted.org/packages/9f/f1/495c03b0e47a8ac7ce42432a8b81a519befdd4245038a1ef65a1cb48e9b2/dsplot-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "36205db681dcb9db7f80504c3320c62c28a885446a65ba4d6671a41adcf5626e",
                "md5": "91ffbd3d109bf5c9f89f208b98078c66",
                "sha256": "6b6e1ee8e74908c45726715a69a7ba07ff2d517b8a73d8937887e311d2ecbf89"
            },
            "downloads": -1,
            "filename": "dsplot-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "91ffbd3d109bf5c9f89f208b98078c66",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 7319,
            "upload_time": "2023-02-24T17:29:34",
            "upload_time_iso_8601": "2023-02-24T17:29:34.736498Z",
            "url": "https://files.pythonhosted.org/packages/36/20/5db681dcb9db7f80504c3320c62c28a885446a65ba4d6671a41adcf5626e/dsplot-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-24 17:29:34",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "dsplot"
}
        
Elapsed time: 0.21112s