Gradient fills for Matplotlib charts using Agg filters
Project description
mpl-gradients
A lightweight, zero-dependency library to add linear gradient fills to Matplotlib charts. Solves matplotlib/matplotlib#30958.
Features
- Vertical Gradients: Fade from Top to Bottom.
- Horizontal Gradients: Fade from Left to Right.
- Diagonal Gradients: Fade from Corner to Corner.
- Alpha Blending: Correctly handles transparency.
Installation
You can install directly from GitHub:
pip install mpl-gradients
Quick start
import matplotlib.pyplot as plt
from mpl_gradients import LinearGradient
fig, ax = plt.subplots()
ax.bar([0, 1, 2], [10, 20, 15])
# Create a gradient (Top-Left Navy -> Bottom-Right Lime)
gradient = LinearGradient("navy", "lime", direction="diagonal")
# Apply to bars
for bar in ax.containers[0]:
bar.set_agg_filter(gradient)
plt.show()
Requirements
Python 3.9+
Matplotlib
Numpy
New in v0.2.0: Transparency Support
You can now create gradients that fade to transparent!
By default, gradients preserve the original alpha of the plot (preserve_alpha=True).
To create transparent gradients (e.g., Red -> Transparent), set preserve_alpha=False.
from mpl_gradients import LinearGradient
# Create a gradient that fades from Red to Transparent to Green
gradient = LinearGradient.from_colors(
["red", "#ffffff00", "green"],
preserve_alpha=False
)
# Apply it
ax.fill_between(x, y, color="blue").set_agg_filter(gradient)
Project details
Release history Release notifications | RSS feed
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 mpl_gradients-0.2.1.tar.gz.
File metadata
- Download URL: mpl_gradients-0.2.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07701085e338f1bd85777917c5519b24195951ce55b77430035c6997a13dc0a8
|
|
| MD5 |
9580303122865db0643f0933f6f4d47e
|
|
| BLAKE2b-256 |
aa9cebbd1e05c0f1f642bd744d6bf81283b72f81e2b0e0638ecbc4d86110377d
|
File details
Details for the file mpl_gradients-0.2.1-py3-none-any.whl.
File metadata
- Download URL: mpl_gradients-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0af64c3c87d4e8c26b3281572be667a5076389c09ecf2f0cfd45919021de59ba
|
|
| MD5 |
34550e8bf756db80ee79fa311e69c9e9
|
|
| BLAKE2b-256 |
3fe3cd695b814ce6dddf66d097d62d28bab8c1c998ec520c8af8f944a94171a0
|