Skip to main content

Sparse matrix spy plot, HTML, and LaTeX rendering with Jupyter integration.

Project description

tests codecov PyPI version

MatSpy

Sparse matrix spy plot and sparkline renderer.

Supports:

  • scipy.sparse sparse matrices and arrays like csr_matrix and coo_array.
  • python-graphblas sparse matrix gb.Matrix. See demo.

See a Jupyter notebook demo.

For HTML/LaTeX see MatRepr.

Quick Start

pip install matspy
from matspy import spy

spy(A)
Spy Plot

Methods

  • spy(A): Plot the sparsity pattern (location of nonzero values) of sparse matrix A.
  • to_sparkline(A): Return a small spy plot as a self-contained HTML string.
  • spy_to_mpl(A): Same as spy() 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. If True, then a matrix description is auto generated.
  • indices: Whether to show matrix indices.
  • figsize, sparkline_size: size of the plot, in inches
  • shading: binary, relative, absolute.
  • buckets: spy plot pixels (longest side).
  • dpi: determine buckets 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.

triple product

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.

sparkline AA

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 a MatrixSpyAdapter 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

matspy-0.6.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

matspy-0.6-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file matspy-0.6.tar.gz.

File metadata

  • Download URL: matspy-0.6.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for matspy-0.6.tar.gz
Algorithm Hash digest
SHA256 49ab8c775962f589aa3d300f27fb52f424426ba6483b252ae44b7d789e1106f6
MD5 e715b6522ce9c64e9776ce00293640fb
BLAKE2b-256 02484f378eedc67d8e0354eb25247af71d6e850714d8dde1813445a1a2f93e56

See more details on using hashes here.

File details

Details for the file matspy-0.6-py3-none-any.whl.

File metadata

  • Download URL: matspy-0.6-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for matspy-0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d9e112f7c58fddf58d849adeac2a3eccbed42099ac921382762f9d5f68fca732
MD5 518df24facb5e03dbf90df6e541918dd
BLAKE2b-256 54ad9c734d5683b9ac52b0fb3757a995b786f9238b4665c7ea8ddfab0b46c0ae

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page