Mathematics for AI Utilities
Project description
Math4AI
Publication-ready figures for mathematics and machine learning — one import away.
Math4AI is the companion library for the Mathematics for AI book and any technical project that generates chapter figures with Python. It gives you a shared visual language: consistent colors, matrix and vector layouts, reusable icons, and mindmaps driven by JSON — so every diagram in a long manuscript looks like it belongs to the same book.
Works on Linux x86_64, Python 3.9+ (3.12 recommended). Dependencies: matplotlib, numpy.
Why Math4AI?
Writing a math or ML book means hundreds of small plotting scripts — one per figure. Without a shared toolkit, colors drift, brace styles diverge, and mindmaps become copy-paste nightmares.
Math4AI fixes that:
- One palette across linear algebra, optimization, probability, and information theory chapters
- Matrix & vector helpers — dashed rows/cols, braces, piercing highlights, affine grids, arrows
- Dozens of built-in icons for mindmaps (SVD, Bellman, KL, Langevin, EM, …)
- JSON mindmaps — declare nodes and edges; render a publication-quality figure from
mindmap.json - Local icon hooks — add a custom shape in one script without forking the library
save_figure_to_script_dir— output lands next to your script, ready for\includegraphics
Built for authors and educators who care how their PDFs look, not just that the code runs.
Get started
From PyPI (release wheel, Linux x86_64):
pip install math4ai
From source (editable dev install):
git clone https://github.com/xuanxinjushi/math4ai.git math4ai-plot
cd math4ai-plot
pip install -e ".[dev]"
Run tests:
pytest
# or: make test
Quick check:
python -c "from math4ai import plane_color; print(plane_color)" # blue
Docker
Build image:
docker build -t math4ai:dev .
Run tests in container:
docker run --rm math4ai:dev
Generate docs icon gallery from container into local repo:
docker run --rm -v "$PWD":/app -w /app math4ai:dev make docs-icons
Open generated gallery at docs/icons.md.
What you can build
| Area | Examples |
|---|---|
| Colors | plane_color, point_x_color, normal_vector_color, … |
| Matrices | Matrix, dashed rows/cols, braces, row/column coloring |
| Vectors | draw_vec, draw_affine_grid, arrow |
| Mindmaps | render_mindmap(__file__) + mindmap.json |
| Icons | QR, LU, SVD, gradient, Bayes, Markov, score field, … |
| Figures | save_figure_to_script_dir, 2D/3D grid styling, math fonts |
A minute of code
Consistent scatter plot
from math4ai import point_x_color, save_figure_to_script_dir
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.scatter([1, 2, 3], [1, 4, 9], color=point_x_color)
save_figure_to_script_dir("example.png")
Mindmap from JSON
from math4ai import render_mindmap
if __name__ == "__main__":
render_mindmap(__file__) # reads mindmap.json beside this script
Custom mindmap icon (local hook)
def draw_my_topic_icon(ax, center_x, center_y, size=0.5):
...
Reference "icon": "my_topic" in mindmap.json — no library patch required.
Who is it for?
- Authors of textbooks and monographs with matplotlib figure pipelines
- Course materials that need repeatable, professional diagrams
- Researchers publishing papers who want book-grade consistency across chapters
Install once, import everywhere your scripts live.
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 Distributions
Built Distributions
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 math4ai-0.0.1.dev0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: math4ai-0.0.1.dev0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 269.0 kB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20cf98a4b0f9eff7e87c30491af0b758db7754f5f2fdf2a89f213879462d5853
|
|
| MD5 |
40ca653f00e549006723907f1d772162
|
|
| BLAKE2b-256 |
a52ad447c95a2b8899c7d47197227f6d1b5c46e8cb31583dc3170a4ee6464b5b
|
File details
Details for the file math4ai-0.0.1.dev0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: math4ai-0.0.1.dev0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 257.6 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b792f7a2cf9de151147a6ff3af4957a4bd1ed0f5c26aca2c54bd7b30d3101ddc
|
|
| MD5 |
18dc949b7cdb62aa1f1f87db2be4b413
|
|
| BLAKE2b-256 |
6ce7f10cb5b45c472fad7dc04fb9b51027485a0f4cd118fc366cc793f3970f07
|
File details
Details for the file math4ai-0.0.1.dev0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: math4ai-0.0.1.dev0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 282.4 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b82528b1254736104c3fe8da61b6e78c89b92699515a7cfbb2856393c74785c1
|
|
| MD5 |
29c18560d973b10bb1ca8e53da00ea92
|
|
| BLAKE2b-256 |
51f5a88643d10ee7bed108d389d1639e255f6473dd39328807d2810b3b5c1acb
|
File details
Details for the file math4ai-0.0.1.dev0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: math4ai-0.0.1.dev0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 187.9 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5258159f02c36595b896cb9c0d5accc96104875f8c71ab51b260c393f0bd478a
|
|
| MD5 |
7916798eb80bd97b0c6cc6ec43fee0a0
|
|
| BLAKE2b-256 |
5ae89facce9217312ca5998b71f115393227263d40d5fa33a26d9df04979ed08
|
File details
Details for the file math4ai-0.0.1.dev0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: math4ai-0.0.1.dev0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 186.0 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3c8611f652824fd89e48825d12bc6653a16e63da93ec47a8f65f6df4cb9ca8b
|
|
| MD5 |
2c4749907cf3fe3b7caf14e8949f64d9
|
|
| BLAKE2b-256 |
9f5f320cc99e261b76f818c82ffb27dfa756a559ba9dc113021552b4053e16a0
|