Skip to main content

mpl-gradients

PyPI version Gradient Demo

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)

Metadata

Release files for mpl-gradients 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mpl-gradients 0.2.1
File Size Uploaded
mpl_gradients-0.2.1.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mpl-gradients 0.2.1
File Interpreter ABI Platform
mpl_gradients-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / mpl_gradients-0.2.1.tar.gz

Download URL mpl_gradients-0.2.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
07701085e338f1bd85777917c5519b24195951ce55b77430035c6997a13dc0a8
BLAKE2b-256 checksum
How to use checksums
aa9cebbd1e05c0f1f642bd744d6bf81283b72f81e2b0e0638ecbc4d86110377d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / mpl_gradients-0.2.1-py3-none-any.whl

Download URL mpl_gradients-0.2.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0af64c3c87d4e8c26b3281572be667a5076389c09ecf2f0cfd45919021de59ba
BLAKE2b-256 checksum
How to use checksums
3fe3cd695b814ce6dddf66d097d62d28bab8c1c998ec520c8af8f944a94171a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page