Skip to main content

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

matplotlib_lossless_webp-1.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matplotlib_lossless_webp-1.1.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file matplotlib_lossless_webp-1.1.1.tar.gz.

File metadata

File hashes

Hashes for matplotlib_lossless_webp-1.1.1.tar.gz
Algorithm Hash digest
SHA256 57364e2c1e2b3d3a5b8323078a6ddb6f3439ee1bc48b534301aac4e9e2bd5b31
MD5 89fab7d5f06287f5f5f61bcf17dba3d0
BLAKE2b-256 b33fea22ce2135ae439e3475f90944ad5a8446f21b5e313cca52f92008d6ff13

See more details on using hashes here.

File details

Details for the file matplotlib_lossless_webp-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for matplotlib_lossless_webp-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d3a1b86c9ba24651a69e5c298f29df697d450bdd3f0619184c2791126d16fb6c
MD5 50786e58e74e18c5a035d1754f3752fc
BLAKE2b-256 f7e9bdb74643229edb2a24e28694c24d1f5cc1c2ee137b7b007da61fbeef273f

See more details on using hashes here.

Supported by

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