Sparse matrix spy plot, HTML, and LaTeX rendering with Jupyter integration.
Project description
MatSpy
Sparse matrix spy plot and sparkline renderer.
Supports:
scipy.sparse
sparse matrices and arrays likecsr_matrix
andcoo_array
.
For HTML/LaTeX see MatRepr.
Quick Start
pip install matspy
from matspy import spy
spy(A)
See a Jupyter notebook demo.
Methods
spy(A)
: Plot the sparsity pattern (location of nonzero values) of sparse matrixA
.to_sparkline(A)
: Return a small spy plot as a self-contained HTML string.spy_to_mpl(A)
: Same asspy()
but returns the matplotlib Figure without showing it.to_spy_heatmap(A)
: Return the raw 2D array for spy plots.
Arguments
All methods take the same arguments. Apart from the matrix itself:
title
: string label. IfTrue
, then a matrix description is auto generated.indices
: Whether to show matrix indices.figsize
,sparkline_size
: size of the plot, in inchesshading
:binary
,relative
,absolute
.buckets
: spy plot pixels (longest side).dpi
: determinebuckets
relative to figure size.
Overriding defaults
matspy.params
contains the default values for all arguments.
For example, to default to binary shading, no title, and no indices:
matspy.params.shading = 'binary'
matspy.params.title = False
matspy.params.indices = False
Jupyter
spy()
simply shows a matplotlib figure and works well within Jupyter.
to_sparkline()
can create small matrix visualizations that work anywhere HTML is displayed.
Multiple sparklines can be automatically to-scale with each other using the retscale
and scale
arguments.
Fast
All operations work with very large matrices. A spy plot of tens of millions of elements takes less than half a second.
Large matrices are downscaled using two native matrix multiplies. The final dense 2D image is small.
Spy Plot Anti-Aliasing
One application of spy plots is to quickly see if a matrix has a noticeable structure. Aliasing artifacts can give the false impression of structure where none exists, such as moiré or even a false grid pattern.
MatSpy employs some simple methods to help eliminate these effects in most cases.
See the Anti-Aliasing demo for more.
How to support more packages
Each package that MatSpy supports implements two classes:
Driver
: Declares what types are supported and supplies an adapter.get_supported_type_prefixes
: This declares what types are supported, as strings to avoid unnecessary imports.adapt_spy(A)
: Returns aMatrixSpyAdapter
for a matrix that this driver supports.
MatrixSpyAdapter
. A common interface for extracting spy data.describe()
: Describes the adapted matrix. This description serves as the plot title.get_shape()
: Returns the adapted matrix's shape.get_spy()
: Returns spy plot data as a dense 2D numpy array.
See matspy/adapters for details.
You may use matspy.register_driver
to register a Driver for your own matrix class.
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
File details
Details for the file matspy-0.5.tar.gz
.
File metadata
- Download URL: matspy-0.5.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 65c35d83d4b33d03a0ed23569b6c49d6327302b4c175c16fa1d79f230ff7a905 |
|
MD5 | b244a49d43a22e0b718870ec9c8209db |
|
BLAKE2b-256 | ba0ce55ca676c836d1ccecd534c2430c0cf0ad934130fc0abf13a3fabbd0c607 |
File details
Details for the file matspy-0.5-py3-none-any.whl
.
File metadata
- Download URL: matspy-0.5-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7c12ab638f19d27f6cd46da09785ef9e0081f45601f98d292420a4b8cda0fe6 |
|
MD5 | e2bd52bdeb6dcd0527aeeac46bc3c8f7 |
|
BLAKE2b-256 | 4ffe79f04f497a52f7cd30221f8e67e4e50b9e84dcaf26599126e9062d64a830 |