Skip to main content

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:

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

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.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

hasse_diagram-1.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file hasse_diagram-1.2.tar.gz.

File metadata

  • Download URL: hasse_diagram-1.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hasse_diagram-1.2.tar.gz
Algorithm Hash digest
SHA256 7aea9a20b0d321676b90d34152b39a8c81825024c05a6cb13713fc33d97acc2b
MD5 0610d2f68a171a2830383c263a7adc18
BLAKE2b-256 661139898773fbbdc0fbbfb15dc610e1701d41742c0b5b83f69e24cd62fdd4d0

See more details on using hashes here.

File details

Details for the file hasse_diagram-1.2-py3-none-any.whl.

File metadata

  • Download URL: hasse_diagram-1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for hasse_diagram-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7a8805e07bf4e0284ea35e33e1038cdc9b5ad92e705989bf07c708d775954c07
MD5 3c6bda1b0aa092e8905b41026c8f6c00
BLAKE2b-256 67ba58e4e2f6cbc5d07fa539fbd6f92bbba78d9e78cb658ae22864e7d01238ec

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