{"id":15046531,"url":"https://github.com/alugowski/matspy","last_synced_at":"2025-10-27T14:31:20.551Z","repository":{"id":189084725,"uuid":"680010906","full_name":"alugowski/matspy","owner":"alugowski","description":"Sparse matrix spy plot and sparkline renderer.","archived":false,"fork":false,"pushed_at":"2024-11-18T23:54:23.000Z","size":1599,"stargazers_count":15,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-01T06:31:46.644Z","etag":null,"topics":["graphblas","matrix","scipy","sparse","sparse-data","sparse-matrices","sparse-matrix","sparsity-pattern","visualization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alugowski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-18T06:17:07.000Z","updated_at":"2025-01-20T01:07:46.000Z","dependencies_parsed_at":"2023-09-22T07:21:32.874Z","dependency_job_id":"3e1fa7d3-b6d2-4d4f-aecb-78825a979ba8","html_url":"https://github.com/alugowski/matspy","commit_stats":{"total_commits":57,"total_committers":2,"mean_commits":28.5,"dds":"0.052631578947368474","last_synced_commit":"b0b59c8c9765206067b988deaafce0c26640c9f8"},"previous_names":["alugowski/matspy"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alugowski%2Fmatspy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alugowski%2Fmatspy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alugowski%2Fmatspy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alugowski%2Fmatspy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alugowski","download_url":"https://codeload.github.com/alugowski/matspy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238508843,"owners_count":19484213,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphblas","matrix","scipy","sparse","sparse-data","sparse-matrices","sparse-matrix","sparsity-pattern","visualization"],"created_at":"2024-09-24T20:53:12.526Z","updated_at":"2025-10-27T14:31:15.121Z","avatar_url":"https://github.com/alugowski.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![tests](https://github.com/alugowski/matspy/actions/workflows/tests.yml/badge.svg)](https://github.com/alugowski/matspy/actions/workflows/tests.yml)\n[![codecov](https://codecov.io/gh/alugowski/matspy/graph/badge.svg?token=m2xJcl5iAQ)](https://codecov.io/gh/alugowski/matspy)\n[![PyPI version](https://badge.fury.io/py/matspy.svg)](https://pypi.org/project/matspy/)\n[![Conda Version](https://img.shields.io/conda/vn/conda-forge/matspy.svg)](https://anaconda.org/conda-forge/matspy)\n\n# MatSpy\n\nSparse matrix spy plot and sparkline renderer.\n\n```python\nfrom matspy import spy\n\nspy(A)\n```\n\n\u003cimg src=\"doc/images/spy.png\" width=\"400\" alt=\"Spy Plot\"/\u003e\n\nSupports:\n* **SciPy** - sparse matrices and arrays like `csr_matrix` and `coo_array` [(demo)](demo.ipynb)\n* **NumPy** - `ndarray` [(demo)](demo-numpy.ipynb)\n* **[Python-graphblas](https://github.com/python-graphblas/python-graphblas)** - `gb.Matrix` [(demo)](demo-python-graphblas.ipynb)\n* **[PyData/Sparse](https://sparse.pydata.org/)** - `COO`, `DOK`, `GCXS`  [(demo)](demo-pydata-sparse.ipynb)\n\nFeatures:\n* Simple `spy()` method plots non-zero structure of a matrix, similar to MatLAB's spy.\n* Sparklines: `to_sparkline()` creates small self-contained spy plots for inline HTML visuals.\n* FAST and handles very large matrices.\n\nSee a [Jupyter notebook demo](demo.ipynb).\n\n```shell\npip install matspy\n```\n```shell\nconda install matspy\n ```\n\n## Methods\n* `spy(A)`: Plot the sparsity pattern (location of nonzero values) of sparse matrix `A`.\n* `to_sparkline(A)`: Return a small spy plot as a self-contained HTML string. Multiple sparklines can be automatically to-scale with each other using the `retscale` and `scale` arguments.\n* `spy_to_mpl(A)`: Same as `spy()` but returns the matplotlib Figure without showing it.\n* `to_spy_heatmap(A)`: Return the raw 2D array for spy plots. \n\n## Examples\n\nSee the [demo notebook](demo.ipynb) for more.\n\n#### Save spy plot as a PNG image\n\n```python\nfig, ax = matspy.spy_to_mpl(A)\nfig.savefig(\"spy.png\", bbox_inches='tight')\n```\n\n## Arguments\n\nAll methods take the same arguments. Apart from the matrix itself:\n\n* `title`: string label. If `True`, then a matrix description is auto generated.\n* `indices`: Whether to show matrix indices.\n* `figsize`, `sparkline_size`: size of the plot, in inches\n* `shading`: `binary`, `relative`, `absolute`.\n* `buckets`: spy plot pixels (longest side).\n* `dpi`: determine `buckets` relative to figure size.\n* `precision`: For numpy arrays, only plot values with magnitude greater than `precision`. Like [matplotlib.pyplot.spy()](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.spy.html)'s `precision`.\n\n### Overriding defaults\n`matspy.params` contains the default values for all arguments.\n\nFor example, to default to binary shading, no title, and no indices:\n\n```python\nmatspy.params.shading = 'binary'\nmatspy.params.title = False\nmatspy.params.indices = False\n```\n\n## Jupyter\n\n`spy()` simply shows a matplotlib figure and works well within Jupyter.\n\n`to_sparkline()` creates small spy plots that work anywhere HTML is displayed.\n\n# Fast\nAll operations work with very large matrices.\nA spy plot of tens of millions of elements takes less than half a second.\n\nLarge matrices are downscaled using two native matrix multiplies. The final dense 2D image is small.\n\n\u003cimg src=\"doc/images/triple_product.png\" height=\"125\" width=\"400\" alt=\"triple product\"/\u003e\n\nNote: the spy plots in this image were created with `to_sparkline()`. Code in the [demo notebook](demo.ipynb).\n\n# Spy Plot Anti-Aliasing\nOne application of spy plots is to quickly see if a matrix has a noticeable structure.\nAliasing artifacts can give the false impression of structure where none exists,\nsuch as moiré or even a false grid pattern.\n\nMatSpy employs some simple methods to help eliminate these effects in most cases.\n\n![sparkline AA](doc/images/sparkline_aa.png)\n\nSee the [Anti-Aliasing demo](demo-anti-aliasing.ipynb) for more.\n\n# How to support more packages\n\nEach package that MatSpy supports implements two classes:\n\n* `Driver`: Declares what types are supported and supplies an adapter.\n  * `get_supported_type_prefixes`: This declares what types are supported, as strings to avoid unnecessary imports.\n  * `adapt_spy(A)`: Returns a `MatrixSpyAdapter` for a matrix that this driver supports.\n* `MatrixSpyAdapter`. A common interface for extracting spy data.\n  * `describe()`: Describes the adapted matrix. This description serves as the plot title.\n  * `get_shape()`: Returns the adapted matrix's shape.\n  * `get_spy()`: Returns spy plot data as a dense 2D numpy array.\n\nSee [matspy/adapters](matspy/adapters) for details.\n\nYou may use `matspy.register_driver` to register a `Driver` for your own matrix class.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falugowski%2Fmatspy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falugowski%2Fmatspy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falugowski%2Fmatspy/lists"}