Skip to main content

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:

img.png

  • 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

Release files for hasse-diagram 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hasse-diagram 1.2
File Size Uploaded
hasse_diagram-1.2.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for hasse-diagram 1.2
File Interpreter ABI Platform
hasse_diagram-1.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.8 kB

Release files / hasse_diagram-1.2.tar.gz

Download URL hasse_diagram-1.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7aea9a20b0d321676b90d34152b39a8c81825024c05a6cb13713fc33d97acc2b
BLAKE2b-256 checksum
How to use checksums
661139898773fbbdc0fbbfb15dc610e1701d41742c0b5b83f69e24cd62fdd4d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / hasse_diagram-1.2-py3-none-any.whl

Download URL hasse_diagram-1.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a8805e07bf4e0284ea35e33e1038cdc9b5ad92e705989bf07c708d775954c07
BLAKE2b-256 checksum
How to use checksums
67ba58e4e2f6cbc5d07fa539fbd6f92bbba78d9e78cb658ae22864e7d01238ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.2 This release

2 release files

1.1

2 release files

1.0

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page