Tiny Python package that forces lossless compression in matplotlib when saving WebP images
Project description
matplotlib-lossless-webp
A tiny Python package that forces lossless compression in matplotlib when saving WebP images.
Otherwise, matplotlib's .webp exports are somewhat low quality unless you set specific PIL parameters.
In this way, you can use .webp as a smaller, drop-in replacement for .png while maintaining perfect quality.
Installation
This project is on PyPI and can be installed with
pip install matplotlib-lossless-webp
Usage
Importing the package will force all future savefig() calls to be lossless when the filename ends with .webp.
import matplotlib.pyplot as plt
import matplotlib_lossless_webp # noqa
plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig('test.webp') # automatically saves as lossless / high quality
Why?
This is mostly for convenience, but scientific figures should normally be lossless, so this is a reasonable default!
Matplotlib is a bit strange for .webp files in that you can't just pass something like savefig(..., quality=100)
or savefig(..., lossless=True).
The (allegedly) intended invocation is to pass the lossless parameter through to PIL with
savefig(..., pil_kwargs={'lossless': True}), but that is cumbersome to add repeatedly.
If this needs to be disabled on a rare, case-by-case basis, this package will not override explicit usage like
savefig(..., pil_kwargs={'lossless': False}).
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matplotlib_lossless_webp-1.1.1.tar.gz.
File metadata
- Download URL: matplotlib_lossless_webp-1.1.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57364e2c1e2b3d3a5b8323078a6ddb6f3439ee1bc48b534301aac4e9e2bd5b31
|
|
| MD5 |
89fab7d5f06287f5f5f61bcf17dba3d0
|
|
| BLAKE2b-256 |
b33fea22ce2135ae439e3475f90944ad5a8446f21b5e313cca52f92008d6ff13
|
File details
Details for the file matplotlib_lossless_webp-1.1.1-py3-none-any.whl.
File metadata
- Download URL: matplotlib_lossless_webp-1.1.1-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3a1b86c9ba24651a69e5c298f29df697d450bdd3f0619184c2791126d16fb6c
|
|
| MD5 |
50786e58e74e18c5a035d1754f3752fc
|
|
| BLAKE2b-256 |
f7e9bdb74643229edb2a24e28694c24d1f5cc1c2ee137b7b007da61fbeef273f
|