mpl-richtext 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mpl_richtext-0.1.0/.gitignore +143 -0
- mpl_richtext-0.1.0/LICENSE +21 -0
- mpl_richtext-0.1.0/MANIFEST.in +0 -0
- mpl_richtext-0.1.0/PKG-INFO +153 -0
- mpl_richtext-0.1.0/README.md +113 -0
- mpl_richtext-0.1.0/examples/basic_usage.py +140 -0
- mpl_richtext-0.1.0/examples/mpl_richtext_examples.png +0 -0
- mpl_richtext-0.1.0/mpl_richtext/__init__.py +12 -0
- mpl_richtext-0.1.0/mpl_richtext/core.py +460 -0
- mpl_richtext-0.1.0/mpl_richtext/version.py +1 -0
- mpl_richtext-0.1.0/mpl_richtext.egg-info/PKG-INFO +153 -0
- mpl_richtext-0.1.0/mpl_richtext.egg-info/SOURCES.txt +18 -0
- mpl_richtext-0.1.0/mpl_richtext.egg-info/dependency_links.txt +1 -0
- mpl_richtext-0.1.0/mpl_richtext.egg-info/requires.txt +8 -0
- mpl_richtext-0.1.0/mpl_richtext.egg-info/top_level.txt +1 -0
- mpl_richtext-0.1.0/pyproject.toml +75 -0
- mpl_richtext-0.1.0/setup.cfg +4 -0
- mpl_richtext-0.1.0/setup.py +67 -0
- mpl_richtext-0.1.0/tests/__init__.py +0 -0
- mpl_richtext-0.1.0/tests/test_basic.py +0 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Unit test / coverage reports
|
|
39
|
+
htmlcov/
|
|
40
|
+
.tox/
|
|
41
|
+
.nox/
|
|
42
|
+
.coverage
|
|
43
|
+
.coverage.*
|
|
44
|
+
.cache
|
|
45
|
+
nosetests.xml
|
|
46
|
+
coverage.xml
|
|
47
|
+
*.cover
|
|
48
|
+
*.py,cover
|
|
49
|
+
.hypothesis/
|
|
50
|
+
.pytest_cache/
|
|
51
|
+
|
|
52
|
+
# Translations
|
|
53
|
+
*.mo
|
|
54
|
+
*.pot
|
|
55
|
+
|
|
56
|
+
# Django stuff:
|
|
57
|
+
*.log
|
|
58
|
+
local_settings.py
|
|
59
|
+
db.sqlite3
|
|
60
|
+
db.sqlite3-journal
|
|
61
|
+
|
|
62
|
+
# Flask stuff:
|
|
63
|
+
instance/
|
|
64
|
+
.webassets-cache
|
|
65
|
+
|
|
66
|
+
# Scrapy stuff:
|
|
67
|
+
.scrapy
|
|
68
|
+
|
|
69
|
+
# Sphinx documentation
|
|
70
|
+
docs/_build/
|
|
71
|
+
|
|
72
|
+
# PyBuilder
|
|
73
|
+
target/
|
|
74
|
+
|
|
75
|
+
# Jupyter Notebook
|
|
76
|
+
.ipynb_checkpoints
|
|
77
|
+
|
|
78
|
+
# IPython
|
|
79
|
+
profile_default/
|
|
80
|
+
ipython_config.py
|
|
81
|
+
|
|
82
|
+
# pyenv
|
|
83
|
+
.python-version
|
|
84
|
+
|
|
85
|
+
# pipenv
|
|
86
|
+
Pipfile.lock
|
|
87
|
+
|
|
88
|
+
# PEP 582
|
|
89
|
+
__pypackages__/
|
|
90
|
+
|
|
91
|
+
# Celery stuff
|
|
92
|
+
celerybeat-schedule
|
|
93
|
+
celerybeat.pid
|
|
94
|
+
|
|
95
|
+
# SageMath parsed files
|
|
96
|
+
*.sage.py
|
|
97
|
+
|
|
98
|
+
# Environments
|
|
99
|
+
.env
|
|
100
|
+
.venv
|
|
101
|
+
env/
|
|
102
|
+
venv/
|
|
103
|
+
ENV/
|
|
104
|
+
env.bak/
|
|
105
|
+
venv.bak/
|
|
106
|
+
|
|
107
|
+
# Spyder project settings
|
|
108
|
+
.spyderproject
|
|
109
|
+
.spyproject
|
|
110
|
+
|
|
111
|
+
# Rope project settings
|
|
112
|
+
.ropeproject
|
|
113
|
+
|
|
114
|
+
# mkdocs documentation
|
|
115
|
+
/site
|
|
116
|
+
|
|
117
|
+
# mypy
|
|
118
|
+
.mypy_cache/
|
|
119
|
+
.dmypy.json
|
|
120
|
+
dmypy.json
|
|
121
|
+
|
|
122
|
+
# Pyre type checker
|
|
123
|
+
.pyre/
|
|
124
|
+
|
|
125
|
+
# IDEs
|
|
126
|
+
.vscode/
|
|
127
|
+
.idea/
|
|
128
|
+
*.swp
|
|
129
|
+
*.swo
|
|
130
|
+
*~
|
|
131
|
+
|
|
132
|
+
# OS
|
|
133
|
+
.DS_Store
|
|
134
|
+
Thumbs.db
|
|
135
|
+
|
|
136
|
+
# Generated images from examples/tests
|
|
137
|
+
*.png
|
|
138
|
+
*.jpg
|
|
139
|
+
*.jpeg
|
|
140
|
+
*.pdf
|
|
141
|
+
!docs/images/*.png
|
|
142
|
+
!docs/images/*.jpg
|
|
143
|
+
!examples/*.png
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Rabin Katel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
File without changes
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mpl-richtext
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Rich text rendering for Matplotlib with multi-color and multi-style support
|
|
5
|
+
Home-page: https://github.com/ra8in/mpl-richtext
|
|
6
|
+
Author: Rabin Katel
|
|
7
|
+
Author-email: Rabin Katel <kattelrabinraja13@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/ra8in/mpl-richtext
|
|
10
|
+
Project-URL: Documentation, https://github.com/ra8in/mpl-richtext#readme
|
|
11
|
+
Project-URL: Repository, https://github.com/ra8in/mpl-richtext
|
|
12
|
+
Project-URL: Bug Tracker, https://github.com/ra8in/mpl-richtext/issues
|
|
13
|
+
Keywords: matplotlib,text,color,rich-text,multi-color,visualization,plotting
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Intended Audience :: Science/Research
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
25
|
+
Classifier: Operating System :: OS Independent
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
33
|
+
Requires-Dist: black>=22.0; extra == "dev"
|
|
34
|
+
Requires-Dist: flake8>=5.0; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=0.990; extra == "dev"
|
|
36
|
+
Dynamic: author
|
|
37
|
+
Dynamic: home-page
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
|
|
41
|
+
# mpl-richtext
|
|
42
|
+
|
|
43
|
+
**Rich text rendering for Matplotlib** - Create beautiful multi-color, multi-style text in a single line.
|
|
44
|
+
|
|
45
|
+
[](https://pypi.org/project/mpl-richtext/)
|
|
46
|
+
[](https://opensource.org/licenses/MIT)
|
|
47
|
+
[](https://www.python.org/downloads/)
|
|
48
|
+
|
|
49
|
+
## Why mpl-richtext?
|
|
50
|
+
|
|
51
|
+
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!
|
|
52
|
+
|
|
53
|
+
**mpl-richtext** solves this by letting you specify colors and styles for each text segment in one simple function call.
|
|
54
|
+
|
|
55
|
+

|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install mpl-richtext
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import matplotlib.pyplot as plt
|
|
67
|
+
from mpl_richtext import richtext
|
|
68
|
+
|
|
69
|
+
fig, ax = plt.subplots()
|
|
70
|
+
|
|
71
|
+
# Create multi-colored text in one line!
|
|
72
|
+
richtext(0.5, 0.5,
|
|
73
|
+
strings=["hello", ", ", "world"],
|
|
74
|
+
colors=["red", "blue", "green"],
|
|
75
|
+
ax=ax, fontsize=20, transform=ax.transAxes)
|
|
76
|
+
|
|
77
|
+
plt.show()
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## Features
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
✨ **Multi-color text** - Different colors for each word or character
|
|
87
|
+
🎨 **Multi-style text** - Mix font sizes, weights, families, and styles (italic/oblique)
|
|
88
|
+
📦 **Flexible input** - Lists, dicts, or tuples for colors and properties
|
|
89
|
+
📏 **Auto word-wrapping** - Specify `box_width` for automatic text wrapping
|
|
90
|
+
🎯 **Full alignment** - Left, center, right horizontal and vertical alignment
|
|
91
|
+
✨ **Decorations** - Support for **underlines** and **background colors**
|
|
92
|
+
🔄 **Transformations** - Support for text **rotation**
|
|
93
|
+
👻 **Transparency** - Support for **alpha** values per segment
|
|
94
|
+
⚡ **Easy to use** - Simple API, works with any Matplotlib axes
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### `richtext(x, y, strings, colors=None, ax=None, **kwargs)`
|
|
101
|
+
|
|
102
|
+
**Parameters:**
|
|
103
|
+
|
|
104
|
+
- **x, y** : `float`
|
|
105
|
+
Starting position of the text
|
|
106
|
+
|
|
107
|
+
- **strings** : `list of str`
|
|
108
|
+
List of text segments, e.g., `["hello", ", ", "world"]`
|
|
109
|
+
|
|
110
|
+
- **colors** : `str`, `list`, or `dict`, optional
|
|
111
|
+
Colors for each segment. Can be:
|
|
112
|
+
- Single string: `"red"` (applies to all)
|
|
113
|
+
- List: `["red", "blue", "green"]` (one per segment)
|
|
114
|
+
- Dict: `{0: "red", 2: "green"}` (specific indices)
|
|
115
|
+
- Tuple keys: `{(0, 2): "red"}` (multiple indices same color)
|
|
116
|
+
|
|
117
|
+
- **ax** : `matplotlib.axes.Axes`, optional
|
|
118
|
+
Axes to draw on. If `None`, uses current axes.
|
|
119
|
+
|
|
120
|
+
- **kwargs** : Additional properties
|
|
121
|
+
- **Global:** `box_width`, `linespacing`, `ha`, `va`, `transform`, `zorder`
|
|
122
|
+
- **Per-segment:** `fontsize`/`fontsizes`, `fontweight`/`fontweights`, `fontfamily`/`fontfamilies`, etc.
|
|
123
|
+
- Any property can be:
|
|
124
|
+
- Single value (applies to all)
|
|
125
|
+
- List (one per segment, auto-extends)
|
|
126
|
+
- Dict (specific indices)
|
|
127
|
+
|
|
128
|
+
**Returns:**
|
|
129
|
+
- `list of Text` - List of created matplotlib Text objects
|
|
130
|
+
|
|
131
|
+
## Contributing
|
|
132
|
+
|
|
133
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
134
|
+
|
|
135
|
+
1. Fork the repository
|
|
136
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
137
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
138
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
139
|
+
5. Open a Pull Request
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
144
|
+
|
|
145
|
+
## Links
|
|
146
|
+
|
|
147
|
+
- **PyPI:** https://pypi.org/project/mpl-richtext/
|
|
148
|
+
- **GitHub:** https://github.com/ra8in/mpl-richtext
|
|
149
|
+
- **Issues:** https://github.com/ra8in/mpl-richtext/issues
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
Made with ❤️ for the Matplotlib community
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# mpl-richtext
|
|
2
|
+
|
|
3
|
+
**Rich text rendering for Matplotlib** - Create beautiful multi-color, multi-style text in a single line.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/mpl-richtext/)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://www.python.org/downloads/)
|
|
8
|
+
|
|
9
|
+
## Why mpl-richtext?
|
|
10
|
+
|
|
11
|
+
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!
|
|
12
|
+
|
|
13
|
+
**mpl-richtext** solves this by letting you specify colors and styles for each text segment in one simple function call.
|
|
14
|
+
|
|
15
|
+

|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install mpl-richtext
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import matplotlib.pyplot as plt
|
|
27
|
+
from mpl_richtext import richtext
|
|
28
|
+
|
|
29
|
+
fig, ax = plt.subplots()
|
|
30
|
+
|
|
31
|
+
# Create multi-colored text in one line!
|
|
32
|
+
richtext(0.5, 0.5,
|
|
33
|
+
strings=["hello", ", ", "world"],
|
|
34
|
+
colors=["red", "blue", "green"],
|
|
35
|
+
ax=ax, fontsize=20, transform=ax.transAxes)
|
|
36
|
+
|
|
37
|
+
plt.show()
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
✨ **Multi-color text** - Different colors for each word or character
|
|
47
|
+
🎨 **Multi-style text** - Mix font sizes, weights, families, and styles (italic/oblique)
|
|
48
|
+
📦 **Flexible input** - Lists, dicts, or tuples for colors and properties
|
|
49
|
+
📏 **Auto word-wrapping** - Specify `box_width` for automatic text wrapping
|
|
50
|
+
🎯 **Full alignment** - Left, center, right horizontal and vertical alignment
|
|
51
|
+
✨ **Decorations** - Support for **underlines** and **background colors**
|
|
52
|
+
🔄 **Transformations** - Support for text **rotation**
|
|
53
|
+
👻 **Transparency** - Support for **alpha** values per segment
|
|
54
|
+
⚡ **Easy to use** - Simple API, works with any Matplotlib axes
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## API Reference
|
|
59
|
+
|
|
60
|
+
### `richtext(x, y, strings, colors=None, ax=None, **kwargs)`
|
|
61
|
+
|
|
62
|
+
**Parameters:**
|
|
63
|
+
|
|
64
|
+
- **x, y** : `float`
|
|
65
|
+
Starting position of the text
|
|
66
|
+
|
|
67
|
+
- **strings** : `list of str`
|
|
68
|
+
List of text segments, e.g., `["hello", ", ", "world"]`
|
|
69
|
+
|
|
70
|
+
- **colors** : `str`, `list`, or `dict`, optional
|
|
71
|
+
Colors for each segment. Can be:
|
|
72
|
+
- Single string: `"red"` (applies to all)
|
|
73
|
+
- List: `["red", "blue", "green"]` (one per segment)
|
|
74
|
+
- Dict: `{0: "red", 2: "green"}` (specific indices)
|
|
75
|
+
- Tuple keys: `{(0, 2): "red"}` (multiple indices same color)
|
|
76
|
+
|
|
77
|
+
- **ax** : `matplotlib.axes.Axes`, optional
|
|
78
|
+
Axes to draw on. If `None`, uses current axes.
|
|
79
|
+
|
|
80
|
+
- **kwargs** : Additional properties
|
|
81
|
+
- **Global:** `box_width`, `linespacing`, `ha`, `va`, `transform`, `zorder`
|
|
82
|
+
- **Per-segment:** `fontsize`/`fontsizes`, `fontweight`/`fontweights`, `fontfamily`/`fontfamilies`, etc.
|
|
83
|
+
- Any property can be:
|
|
84
|
+
- Single value (applies to all)
|
|
85
|
+
- List (one per segment, auto-extends)
|
|
86
|
+
- Dict (specific indices)
|
|
87
|
+
|
|
88
|
+
**Returns:**
|
|
89
|
+
- `list of Text` - List of created matplotlib Text objects
|
|
90
|
+
|
|
91
|
+
## Contributing
|
|
92
|
+
|
|
93
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
94
|
+
|
|
95
|
+
1. Fork the repository
|
|
96
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
97
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
98
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
99
|
+
5. Open a Pull Request
|
|
100
|
+
|
|
101
|
+
## License
|
|
102
|
+
|
|
103
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
104
|
+
|
|
105
|
+
## Links
|
|
106
|
+
|
|
107
|
+
- **PyPI:** https://pypi.org/project/mpl-richtext/
|
|
108
|
+
- **GitHub:** https://github.com/ra8in/mpl-richtext
|
|
109
|
+
- **Issues:** https://github.com/ra8in/mpl-richtext/issues
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
Made with ❤️ for the Matplotlib community
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Basic usage examples for mpl-richtext showcasing various features.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
|
+
from mpl_richtext import richtext
|
|
7
|
+
|
|
8
|
+
def create_example():
|
|
9
|
+
# Set up a clean figure
|
|
10
|
+
fig = plt.figure(figsize=(15, 12), facecolor='white')
|
|
11
|
+
fig.suptitle('mpl-richtext Feature Showcase', fontsize=24, fontweight='bold', y=0.95)
|
|
12
|
+
|
|
13
|
+
# 1. Colors & Gradients
|
|
14
|
+
ax1 = fig.add_subplot(3, 3, 1)
|
|
15
|
+
ax1.axis('off')
|
|
16
|
+
ax1.set_title('1. Multi-Color Text', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
17
|
+
|
|
18
|
+
richtext(0.5, 0.6,
|
|
19
|
+
strings=["Red", "Blue", "Green", "Purple"],
|
|
20
|
+
colors=["#E74C3C", "#3498DB", "#2ECC71", "#9B59B6"],
|
|
21
|
+
fontsize=24, fontweight='bold',
|
|
22
|
+
ha='center', va='center', ax=ax1)
|
|
23
|
+
|
|
24
|
+
richtext(0.5, 0.3,
|
|
25
|
+
strings=list("RAINBOW"),
|
|
26
|
+
colors=["red", "orange", "gold", "green", "blue", "indigo", "violet"],
|
|
27
|
+
fontsize=18, fontweight='bold',
|
|
28
|
+
ha='center', va='center', ax=ax1)
|
|
29
|
+
|
|
30
|
+
# 2. Font Styles & Weights
|
|
31
|
+
ax2 = fig.add_subplot(3, 3, 2)
|
|
32
|
+
ax2.axis('off')
|
|
33
|
+
ax2.set_title('2. Fonts & Styles', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
34
|
+
|
|
35
|
+
richtext(0.5, 0.7,
|
|
36
|
+
strings=["Bold", "Italic", "Light"],
|
|
37
|
+
colors=["black"]*3,
|
|
38
|
+
fontweights=["bold", "normal", "light"],
|
|
39
|
+
fontstyles=["normal", "italic", "normal"],
|
|
40
|
+
fontsize=20, ha='center', ax=ax2)
|
|
41
|
+
|
|
42
|
+
richtext(0.5, 0.4,
|
|
43
|
+
strings=["Serif", "Sans", "Mono"],
|
|
44
|
+
colors=["#34495E"]*3,
|
|
45
|
+
fontfamilies=["serif", "sans-serif", "monospace"],
|
|
46
|
+
fontsize=18, ha='center', ax=ax2)
|
|
47
|
+
|
|
48
|
+
# 3. Decorations (Underline & Background)
|
|
49
|
+
ax3 = fig.add_subplot(3, 3, 3)
|
|
50
|
+
ax3.axis('off')
|
|
51
|
+
ax3.set_title('3. Decorations', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
52
|
+
|
|
53
|
+
richtext(0.5, 0.7,
|
|
54
|
+
strings=["Underlined", "Text"],
|
|
55
|
+
colors=["#2C3E50", "#E67E22"],
|
|
56
|
+
underlines=[True, True],
|
|
57
|
+
fontsize=20, ha='center', ax=ax3)
|
|
58
|
+
|
|
59
|
+
richtext(0.5, 0.3,
|
|
60
|
+
strings=[" Highlighted ", " Box "],
|
|
61
|
+
colors=["white", "black"],
|
|
62
|
+
backgroundcolors=["#E74C3C", "#F1C40F"],
|
|
63
|
+
fontsize=18, ha='center', ax=ax3)
|
|
64
|
+
|
|
65
|
+
# 4. Sizing & Spacing
|
|
66
|
+
ax4 = fig.add_subplot(3, 3, 4)
|
|
67
|
+
ax4.axis('off')
|
|
68
|
+
ax4.set_title('4. Sizes & Spacing', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
69
|
+
|
|
70
|
+
richtext(0.5, 0.5,
|
|
71
|
+
strings=["Small", "Medium", "Large"],
|
|
72
|
+
colors=["#7F8C8D", "#34495E", "#2C3E50"],
|
|
73
|
+
fontsizes=[12, 20, 32],
|
|
74
|
+
ha='center', va='center', ax=ax4)
|
|
75
|
+
|
|
76
|
+
# 5. Syntax Highlighting (Code)
|
|
77
|
+
ax5 = fig.add_subplot(3, 3, 5)
|
|
78
|
+
ax5.axis('off')
|
|
79
|
+
ax5.set_title('5. Syntax Highlighting', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
80
|
+
|
|
81
|
+
richtext(0.1, 0.6,
|
|
82
|
+
strings=["def ", "hello_world", "():"],
|
|
83
|
+
colors=["#C678DD", "#61AFEF", "#ABB2BF"],
|
|
84
|
+
fontfamily='monospace', fontsize=16, ax=ax5)
|
|
85
|
+
|
|
86
|
+
richtext(0.1, 0.4,
|
|
87
|
+
strings=[" return ", "'Success!'"],
|
|
88
|
+
colors=["#C678DD", "#98C379"],
|
|
89
|
+
fontfamily='monospace', fontsize=16, ax=ax5)
|
|
90
|
+
|
|
91
|
+
# 6. Advanced Alignment
|
|
92
|
+
ax6 = fig.add_subplot(3, 3, 6)
|
|
93
|
+
ax6.axis('off')
|
|
94
|
+
ax6.set_title('6. Alignment', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
95
|
+
|
|
96
|
+
richtext(0.5, 0.8, ["Left Aligned"], ["black"], ha='left', fontsize=14, ax=ax6)
|
|
97
|
+
richtext(0.5, 0.5, ["Center Aligned"], ["#E67E22"], ha='center', fontsize=14, ax=ax6)
|
|
98
|
+
richtext(0.5, 0.2, ["Right Aligned"], ["#2980B9"], ha='right', fontsize=14, ax=ax6)
|
|
99
|
+
ax6.axvline(0.5, color='#BDC3C7', linestyle='--', zorder=0)
|
|
100
|
+
|
|
101
|
+
# 7. Targeted Overrides (Dictionary)
|
|
102
|
+
ax7 = fig.add_subplot(3, 3, 7)
|
|
103
|
+
ax7.axis('off')
|
|
104
|
+
ax7.set_title('7. Targeted Overrides', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
105
|
+
|
|
106
|
+
richtext(0.5, 0.5,
|
|
107
|
+
strings=["Normal", "Red", "Normal", "Blue"], color="green",
|
|
108
|
+
colors={1: "red", 3: "blue"}, fontsizes={1: 20, 3: 30}, fontsize=15, # Target specific indices
|
|
109
|
+
fontweights={1: "bold", 3: "bold"},
|
|
110
|
+
ha='center', va='center', ax=ax7)
|
|
111
|
+
|
|
112
|
+
# 8. Rotated Text
|
|
113
|
+
ax8 = fig.add_subplot(3, 3, 8)
|
|
114
|
+
ax8.axis('off')
|
|
115
|
+
ax8.set_title('8. Rotated Text', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
116
|
+
|
|
117
|
+
richtext(0.5, 0.5,
|
|
118
|
+
strings=["Rotated ", "Text"],
|
|
119
|
+
colors=["#8E44AD", "#2C3E50"],
|
|
120
|
+
rotation=45,
|
|
121
|
+
fontsize=24, ha='center', va='center', ax=ax8)
|
|
122
|
+
|
|
123
|
+
# 9. Transparency (Alpha)
|
|
124
|
+
ax9 = fig.add_subplot(3, 3, 9)
|
|
125
|
+
ax9.axis('off')
|
|
126
|
+
ax9.set_title('9. Transparency', loc='left', fontsize=14, fontweight='bold', pad=10)
|
|
127
|
+
|
|
128
|
+
richtext(0.5, 0.5,
|
|
129
|
+
strings=["Solid", "Fade", "Ghost"],
|
|
130
|
+
colors=["#2C3E50"]*3,
|
|
131
|
+
alphas=[1.0, 0.6, 0.2],
|
|
132
|
+
fontsize=24, fontweight='bold',
|
|
133
|
+
ha='center', va='center', ax=ax9)
|
|
134
|
+
|
|
135
|
+
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
|
|
136
|
+
plt.savefig('examples/mpl_richtext_examples.png', dpi=200, bbox_inches='tight')
|
|
137
|
+
print("Example image saved.")
|
|
138
|
+
|
|
139
|
+
if __name__ == "__main__":
|
|
140
|
+
create_example()
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mpl-richtext: Rich text rendering for Matplotlib
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from .core import richtext
|
|
6
|
+
from .version import __version__
|
|
7
|
+
|
|
8
|
+
__all__ = ['richtext', '__version__']
|
|
9
|
+
|
|
10
|
+
__author__ = 'Rabin Katel'
|
|
11
|
+
__email__ = 'kattelrabinraja13@gmail.com'
|
|
12
|
+
__license__ = 'MIT'
|