Skip to main content

Gradient fills for Matplotlib charts using Agg filters

Project description

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)

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

mpl_gradients-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

mpl_gradients-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file mpl_gradients-0.2.0.tar.gz.

File metadata

  • Download URL: mpl_gradients-0.2.0.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

Hashes for mpl_gradients-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f99c549f385d05a2a91017699e0b62e4171a11f9abb120924dbac1da9f9ba8ee
MD5 44813637d5030fbf7cd2e34441cf7fdb
BLAKE2b-256 28090f019bbc09012504debc3db9f26e85588c0a9727c62ae777e3c049006880

See more details on using hashes here.

File details

Details for the file mpl_gradients-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mpl_gradients-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for mpl_gradients-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 975313c26fefc2b3598cf0c87fcdcc6001867a7633961c09bea8518526019555
MD5 2a1ddf082549037f84a010bd9a91c737
BLAKE2b-256 d8238272af661fe18d74e224cc7c05ccf372b56fea2e2a70b78a74bb366aa7bc

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