Skip to main content

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.

PyPI version License: MIT Python 3.8+

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.

mpl-richtext Showcase

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, or dict, 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)
  • ax : matplotlib.axes.Axes, optional
    Axes to draw on. If None, 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)

Returns:

  • list of Text - List of created matplotlib Text objects

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Links


Made with ❤️ for the Matplotlib community

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_richtext-0.1.3.1.tar.gz (235.5 kB view details)

Uploaded Source

Built Distribution

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

mpl_richtext-0.1.3.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file mpl_richtext-0.1.3.1.tar.gz.

File metadata

  • Download URL: mpl_richtext-0.1.3.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

Hashes for mpl_richtext-0.1.3.1.tar.gz
Algorithm Hash digest
SHA256 7bba4c9b31ed1e60a8a2d60b7e74f79a26cb42afb8f9df1644a35e4544108f27
MD5 5d06afe1311c124d48c94fb65d698bd1
BLAKE2b-256 136a7449da55152943bb0bf6265e70fc7aaa3d460dd67fa4e93d6703a0f55956

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpl_richtext-0.1.3.1.tar.gz:

Publisher: publish.yml on ra8in/mpl-richtext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mpl_richtext-0.1.3.1-py3-none-any.whl.

File metadata

  • Download URL: mpl_richtext-0.1.3.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mpl_richtext-0.1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6fc251c78bc48a222039018a7b29765a2f2a50334975482cd32838d0fca8ea2d
MD5 d1a35e2eec338f783b5dd19a1cd97872
BLAKE2b-256 54f6f017d89de91b533bb24a2b4ab67b540a1ebe325827950ead07c2de7f231e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpl_richtext-0.1.3.1-py3-none-any.whl:

Publisher: publish.yml on ra8in/mpl-richtext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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