Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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.

Metadata

Release files for math4ai 0.0.1.dev0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for math4ai 0.0.1.dev0
File
math4ai-0.0.1.dev0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64, Linux glibc 2.28+ x86-64 Details
math4ai-0.0.1.dev0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
math4ai-0.0.1.dev0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
math4ai-0.0.1.dev0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details
math4ai-0.0.1.dev0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ x86-64, Linux glibc 2.17+ x86-64 Details

Total release size: 1.2 MB

Release files / math4ai-0.0.1.dev0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL math4ai-0.0.1.dev0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 269.0 kB
Tags CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
20cf98a4b0f9eff7e87c30491af0b758db7754f5f2fdf2a89f213879462d5853
BLAKE2b-256 checksum
How to use checksums
a52ad447c95a2b8899c7d47197227f6d1b5c46e8cb31583dc3170a4ee6464b5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / math4ai-0.0.1.dev0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL math4ai-0.0.1.dev0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 257.6 kB
Tags CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b792f7a2cf9de151147a6ff3af4957a4bd1ed0f5c26aca2c54bd7b30d3101ddc
BLAKE2b-256 checksum
How to use checksums
6ce7f10cb5b45c472fad7dc04fb9b51027485a0f4cd118fc366cc793f3970f07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / math4ai-0.0.1.dev0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL math4ai-0.0.1.dev0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 282.4 kB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b82528b1254736104c3fe8da61b6e78c89b92699515a7cfbb2856393c74785c1
BLAKE2b-256 checksum
How to use checksums
51f5a88643d10ee7bed108d389d1639e255f6473dd39328807d2810b3b5c1acb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / math4ai-0.0.1.dev0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL math4ai-0.0.1.dev0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 187.9 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
5258159f02c36595b896cb9c0d5accc96104875f8c71ab51b260c393f0bd478a
BLAKE2b-256 checksum
How to use checksums
5ae89facce9217312ca5998b71f115393227263d40d5fa33a26d9df04979ed08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Release files / math4ai-0.0.1.dev0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl

Download URL math4ai-0.0.1.dev0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Size 186.0 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
b3c8611f652824fd89e48825d12bc6653a16e63da93ec47a8f65f6df4cb9ca8b
BLAKE2b-256 checksum
How to use checksums
9f5f320cc99e261b76f818c82ffb27dfa756a559ba9dc113021552b4053e16a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.11

Security for math4ai 0.0.1.dev0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page