Plot Hasse Diagram in Python
Project description
Hasse Diagram
This small package helps with plotting Hasse Diagrams and is very useful when presenting results for the MCDA methods.
Installation
pip install hasse-diagram
Example usage
Networkx
import numpy as np
from hassediagram import plot_hasse
data = np.array([
[0, 1, 1, 1, 1],
[0, 0, 1, 0, 1],
[0, 1, 0, 0, 1],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]
])
labels = ["node a", "node b", "node c", "node d", "node e"]
plot_hasse(data, labels)
Result:
-
Graphviz dotstring
import numpy as np
from hassediagram import hasse_graphviz
data = np.array([
[0, 1, 1, 1, 1],
[0, 0, 1, 0, 1],
[0, 1, 0, 0, 1],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]
])
labels = ["node a", "node b", "node c", "node d", "node e"]
print(hasse_graphviz(data, labels))
Result:
digraph {
graph [bgcolor="#FFFFFF"]
node [color="#E2E8F0" fontname="Segoe UI" fontsize="15 pt" style=filled]
edge [arrowhead=vee color=black]
compound=true
node1 [label="node a"]
node2 [label="node b, node c"]
node3 [label="node d"]
node4 [label="node e"]
node1 -> node2
node1 -> node3
node2 -> node4
subgraph cluster_1 {
rank=same
peripheries=0
}
subgraph cluster_2 {
rank=same
node1
peripheries=0
}
subgraph cluster_3 {
rank=same
node2
node3
peripheries=0
}
subgraph cluster_4 {
rank=same
node4
peripheries=0
}
}
You can optionally turn off the transitive reduction and change the color of nodes and edges.
Testing
pytest --cov=src --cov-report=term-missing
This package is inspired by a similar one for R: hasseDiagram
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
hasse_diagram-1.1.tar.gz
(6.3 kB
view hashes)
Built Distribution
Close
Hashes for hasse_diagram-1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04e90098b43249385c06d62e5261773b1b993817306a8d61666ded8920171d4f |
|
MD5 | 5ddc5e70e612148e1927e1ebff845641 |
|
BLAKE2b-256 | 0de01deb990b2adae3401a56060b23f529977f710c967fb96d48560399e14640 |