hmmviz
A package for visualizing state transition graphs from hidden Markov models or other models.
This package is meant to serve as an out-of-the-box means of plotting small graphs (less than 10 nodes) in a customizable way.
Installation
Developed with Python 3.6
pip install hmmviz
Usage
Each graph object takes a pandas DataFrame with states indices and columns and transition probabilities (from index to column). However, these can be instantiated using different data structures such as numpy arrays, networkx graphs, etc. (help needed) via the appropriate class methods. as values.
Plotting a Transition Matrix from a Markov Process
from hmmviz import TransGraph
import pandas as pd
import matplotlib.pyplot as plt
sequence = ['sunny', 'sunny', 'rainy', 'rainy', 'sunny', 'sunny', 'sunny', 'rainy']
T = pd.crosstab(
pd.Series(sequence[:-1], name='Today'),
pd.Series(sequence[1:], name='Tomorrow'),
normalize=0
)
# Tomorrow rainy sunny
# Today
# rainy 0.5 0.5
# sunny 0.4 0.6
graph = TransGraph(T)
# looks best on square figures/axes
fig = plt.figure(figsize=(6, 6))
graph.draw()
plt.show()
This will make an all black graph with labels on the nodes but none on the edges.
If we want to make the graph more colorful and informative we can pass some parameters into the graph's draw method.
# same T as before
graph = TransGraph(T)
fig = plt.figure(figsize=(6, 6))
nodelabels = {'sunny': '☁☀', 'rainy': '😊☂'}
colors = {'sunny': 'orange', 'rainy': 'blue'}
graph.draw(
nodelabels=nodelabels, nodecolors=colors, edgecolors=colors, edgelabels=True,
nodefontsize=16,
)
plt.show()
hmmviz really shines for graphs with 4 or 5 nodes. For larger graphs consider using a package like nxviz.
import numpy as np
arr = np.ones((4, 4)) * 0.25
labels = ['s0', 's1', 's2', 's3']
graph = TransGraph.from_array(arr, labels)
colors = {f's{i}': f'C{i}' for i in range(4)}
plt.figure(figsize=(6, 6))
graph.draw(edgecolors=colors, nodecolors=colors, nodelabels=False, edgewidths=2)
plt.show()
Metadata
Release files for hmmviz 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hmmviz-0.0.7.tar.gz | 5.4 kB | Without provenance | Details for hmmviz-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hmmviz-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for hmmviz-0.0.7-py3-none-any.whl |
Total release size: 11.5 kB
Release files / hmmviz-0.0.7.tar.gz
| Download URL | hmmviz-0.0.7.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
412956b5f4838aa6d1fb8ed250e1c2e7029950b14ff44614c287d5de6ee0fdf0
|
|
BLAKE2b-256 checksum How to use checksums |
cbfaef2229eb2c6c1d80a2e4ceae33c1dceb7ebcfa03ba323e0c47c9c8ac32c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.9
|
Release files / hmmviz-0.0.7-py3-none-any.whl
| Download URL | hmmviz-0.0.7-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20ffc9f98258377d1a8c5fc39cd65b81759a29ed60bc25fdfc44a2942d53bbf0
|
|
BLAKE2b-256 checksum How to use checksums |
1bfc53fd497a3f68911f44fc88844efa96bbb7b55c8777e702109dd369909fc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.9
|
Security for hmmviz 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.