Pydot _flow_ makes it a little easier to assemble simple flowing graphs using Pydot.
Project description
Pydot flow
A flowing application programming interface for creating Graphviz visualizations using Pydot.
Introduction
Pydot flow makes it a little easier to assemble simple flowing graphs using Pydot.
You can, for example, use flow to construct a graph programmatically at each step of a data transformation pipeline - visually documenting a data transformation.
Example
In this hypothetical copy-and-paste example a hypothetical graph is constructed using the flow API.
Instructions
- Import dependencies.
- Define a function for creating a random color code.
- Create a Pydot flow Chart.
- Set Node defaults.
- Create the first Node and name it Node 1.
- Flow south from Node 1 to Node 2a.
- Flow east from Node 2a to Node 2b; step into a new subgraph with rank set to same.
- Flow south from Node 2b to Node 3c; step back into the parent graph - break rank.
- Return to Node 2a and flow south from Node 2a to Node 3a.
- Return again to Node 2a and flow south from Node 2a to Node 3b.
- Save the graph image to a file.
- Output an image in a Jupyter Notebook.
Implementation
# 0. Import dependencies.
import random
import pydot
from pydot_flow import Chart
from IPython.display import Image
# 1. Define a function for creating a random color code.
def random_color():
"Generate a random color."
return "#" + hex(random.randint(0, 0xFFFFFF))[2:].rjust(6, "0")
# 2. Create a Pydot flow Chart.
chart = Chart(
rankdir="TB", splines="false", label="Chart", labelloc="t", fontname="Sans", pad=0.2
)
# 3. Set Node defaults.
chart.get_graph().set_node_defaults(style="filled")
# 4. Create the first Node and name it Node 1.
node_1 = chart.create_node(src_node_attrs={"label": "Node 1", "color": random_color()})
# 5. Flow south from Node 1 to Node 2a.
node_2a = node_1.flow(
src_port="s",
dst_node_attrs={"label": "Node 2a", "shape": "diamond", "color": random_color()},
edge_attrs={"label": "Edge 1-2"},
)
# 6. Flow east from Node 2a to Node 2b; step into a new subgraph with rank set to same.
node_2b = node_2a.flow(
src_port="e",
dst_node_attrs={"label": "Node 2b", "color": random_color()},
edge_attrs={"label": "Edge 2a-2b", "minlen": 2},
graph=pydot.Subgraph(rank="same"),
)
# 7. Flow south from Node 2b to Node 3c; step back into the parent graph - break rank.
node_3c = node_2b.flow(
src_port="s",
dst_node_attrs={"label": "Node 3c", "color": random_color()},
edge_attrs={"label": "Edge 2b-3c", "minlen": 2},
graph=chart.get_graph(),
)
# 8. Return to Node 2a and flow south from Node 2a to Node 3a.
node_3a = node_2a.flow(
src_port="s",
dst_node_attrs={"label": "Node 3a", "shape": "box", "color": random_color()},
edge_attrs={"label": "Edge 2a-3a", "minlen": 2, "labeldistance": 2},
)
# 9. Return again to Node 2a and flow south from Node 2a to Node 3b.
node_3b = node_2a.flow(
src_port="s",
dst_node_attrs={"label": "Node 3b", "shape": "box", "color": random_color()},
edge_attrs={"label": "Edge 2a-3b", "minlen": 2},
)
# 10. Save the graph image to a file.
chart.get_graph().write_png("output.png")
# 11. Output an image in a Jupyter Notebook.
Image(chart.get_graph().create_png())
Output
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
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 pydot_flow-0.3.0.tar.gz.
File metadata
- Download URL: pydot_flow-0.3.0.tar.gz
- Upload date:
- Size: 126.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
037fb267352ea3d35e0339839a6d097fbf59d20eab795a3ae3dc352f7a9f2642
|
|
| MD5 |
762c3ce0cbbe48ee1cd53d7fd268034b
|
|
| BLAKE2b-256 |
94541a5df3ab91608eefa1796ebdde0ffb61954863e8f682d896db3f54f3dfee
|
File details
Details for the file pydot_flow-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pydot_flow-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c8528c0c6791941525f61dcefc18b8ada347a623c75fddf5d102b48aba9c4b4
|
|
| MD5 |
3c4bc28063294cd457a0742c56b61855
|
|
| BLAKE2b-256 |
6cc79d1d5e54ec53bfcc3e6d4bb1b90624f8e92ecc1d4da81f893cdfa8a15447
|