Rich text rendering for Matplotlib with multi-color and multi-style support
Project description
mpl-richtext
Rich text rendering for Matplotlib - Create beautiful multi-color, multi-style text in a single line.
Why mpl-richtext?
Standard Matplotlib only supports single-color text. To create multi-colored text, you need to manually position each piece and calculate spacing - tedious and error-prone!
mpl-richtext solves this by letting you specify colors and styles for each text segment in one simple function call.
Installation
pip install mpl-richtext
Quick Start
import matplotlib.pyplot as plt
from mpl_richtext import richtext
fig, ax = plt.subplots()
# Create multi-colored text in one line!
richtext(0.5, 0.5,
strings=["hello", ", ", "world"],
colors=["red", "blue", "green"],
ax=ax, fontsize=20, transform=ax.transAxes)
plt.show()
Features
✨ Multi-color text - Different colors for each word or character
🎨 Multi-style text - Mix font sizes, weights, families, and styles (italic/oblique)
📦 Flexible input - Lists, dicts, or tuples for colors and properties
📏 Auto word-wrapping - Specify box_width for automatic text wrapping
🎯 Full alignment - Left, center, right horizontal and vertical alignment
✨ Decorations - Support for underlines and background colors
🔄 Transformations - Support for text rotation
👻 Transparency - Support for alpha values per segment
⚡ Easy to use - Simple API, works with any Matplotlib axes
API Reference
richtext(x, y, strings, colors=None, ax=None, **kwargs)
Parameters:
-
x, y :
float
Starting position of the text -
strings :
list of str
List of text segments, e.g.,["hello", ", ", "world"] -
colors :
str,list, ordict, optional
Colors for each segment. Can be:- Single string:
"red"(applies to all) - List:
["red", "blue", "green"](one per segment) - Dict:
{0: "red", 2: "green"}(specific indices) - Tuple keys:
{(0, 2): "red"}(multiple indices same color)
- Single string:
-
ax :
matplotlib.axes.Axes, optional
Axes to draw on. IfNone, uses current axes. -
kwargs : Additional properties
- Global:
box_width,linespacing,ha,va,transform,zorder - Per-segment:
fontsize/fontsizes,fontweight/fontweights,fontfamily/fontfamilies, etc. - Any property can be:
- Single value (applies to all)
- List (one per segment, auto-extends)
- Dict (specific indices)
- Global:
Returns:
list of Text- List of created matplotlib Text objects
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Links
- PyPI: https://pypi.org/project/mpl-richtext/
- GitHub: https://github.com/ra8in/mpl-richtext
- Issues: https://github.com/ra8in/mpl-richtext/issues
Made with ❤️ for the Matplotlib community
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_richtext-0.1.1.tar.gz.
File metadata
- Download URL: mpl_richtext-0.1.1.tar.gz
- Upload date:
- Size: 235.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7588e63449029cdef6503f78b00416b669eef8ee729181013e81f9b60112c4b9
|
|
| MD5 |
108b79710b139161a6850ef831cd1a15
|
|
| BLAKE2b-256 |
0a0e58e51a20a863ab97f546fa48a96a20ed1fb7346420e48bd7ec9ec62b4209
|
Provenance
The following attestation bundles were made for mpl_richtext-0.1.1.tar.gz:
Publisher:
publish.yml on ra8in/mpl-richtext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mpl_richtext-0.1.1.tar.gz -
Subject digest:
7588e63449029cdef6503f78b00416b669eef8ee729181013e81f9b60112c4b9 - Sigstore transparency entry: 774600045
- Sigstore integration time:
-
Permalink:
ra8in/mpl-richtext@8dc12159301134d059407dc45af6d8d702494335 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ra8in
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8dc12159301134d059407dc45af6d8d702494335 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mpl_richtext-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mpl_richtext-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5474b9bb86f6d8ca52ba3b78aa71703ef517a075b36bf4f6c911f21533c4b337
|
|
| MD5 |
2c26302038288e38416d3f6bd72b2fb4
|
|
| BLAKE2b-256 |
15691b24a2315c7f7c2b7e8913c2d6dbb03afa060bccb5bd837d449e27de0b54
|
Provenance
The following attestation bundles were made for mpl_richtext-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on ra8in/mpl-richtext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mpl_richtext-0.1.1-py3-none-any.whl -
Subject digest:
5474b9bb86f6d8ca52ba3b78aa71703ef517a075b36bf4f6c911f21533c4b337 - Sigstore transparency entry: 774600046
- Sigstore integration time:
-
Permalink:
ra8in/mpl-richtext@8dc12159301134d059407dc45af6d8d702494335 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/ra8in
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8dc12159301134d059407dc45af6d8d702494335 -
Trigger Event:
release
-
Statement type: