Skip to main content

MathViz

Interactive Mathematical Visualization Library for Python

MathViz makes it easy to explore mathematical concepts through interactive plots, real-time parameter sliders, hover tooltips, and full Jupyter Notebook support.


Features

  • Algebra Visualizer — quadratic & polynomial explorers with live sliders (vertex, roots, discriminant)
  • Calculus Visualizer — derivative + tangent-line visualizer; definite integral with shaded area and symbolic result
  • Linear Algebra Visualizer (v0.2.0+) — 2D matrix transformations, eigenvector discovery mode with complex eigenvalue support
  • Statistics Visualizer (v0.2.0+) — hypothesis testing (Type-I/II error, power analysis) and Bayesian updating (Beta-Binomial inference)
  • Series Visualizer (v0.3.0+) — Taylor Polynomial "Unwrapper" with radius-of-convergence shading; Fourier Epicycle Engine (rotating-circle animation that traces square/sawtooth/triangle/custom waves)
  • DiffEq Visualizer (v0.3.0+) — Interactive Slope Field Dropper (click to drop RK4-integrated solution curves); Predator-Prey Phase Plane (Lotka-Volterra system with a draggable initial condition)
  • General-purpose tools — multi-function plotter, parametric curves, function explorer with auto feature detection
  • Hover tooltips via mplcursors — see exact x/y values and slope on hover
  • Jupyter support — two integration layers:
    • JupyterMathViz — ipywidgets slider-only interface
    • JupyterSimpleMathViz — fully native ipywidgets (safe text input, no keyboard shortcut conflicts)
  • Widget wrappers — thin Slider, Button, InputBox classes over matplotlib.widgets
  • Example gallery — built-in algebra, calculus, and advanced demos
  • Save figures — export any visualization as PNG at arbitrary DPI

Installation

From PyPI

pip install mathvizpro

With Jupyter support

pip install mathvizpro[jupyter]

From source (development)

git clone https://github.com/HORRIDBEAST/MathViz---The-Ultimate-Math-Py-Library.git
cd MathViz---The-Ultimate-Math-Py-Library
pip install -e .

Requirements

Package Version
Python ≥ 3.8
numpy ≥ 1.21.0
matplotlib ≥ 3.5.0
sympy ≥ 1.9.0
mplcursors ≥ 0.5.0
ipywidgets (optional) ≥ 7.6.0

⚠️ Install name vs import name

pip install mathvizpro      # install name on PyPI
import mathviz              # import name in your code
from mathviz import AlgebraVisualizer, CalculusVisualizer

The package is published as mathvizpro on PyPI (the name mathviz was already taken).
The Python import name is still mathviz — this is intentional and common (e.g. pip install Pillow → import PIL).


Quick Start

import mathviz
mathviz.print_info()   # version check
mathviz.quick_start()  # usage guide

Usage

Algebra — Quadratic Explorer

from mathviz import AlgebraVisualizer
import matplotlib.pyplot as plt

viz = AlgebraVisualizer()
viz.quadratic_explorer(
    a_range=(-3, 3),
    b_range=(-5, 5),
    c_range=(-5, 5),
    x_range=(-8, 8)
)
plt.show()

Sliders control a, b, c. The vertex and roots update in real-time. Hover over the curve for exact values.

Algebra — Polynomial Explorer

viz.polynomial_explorer(degree=4, x_range=(-3, 3))
plt.show()

Supports degree 2–5. One slider per coefficient.

Calculus — Derivative Visualizer

from mathviz import CalculusVisualizer

calc = CalculusVisualizer()
calc.derivative_visualizer(
    func_str="x**3 - 3*x**2 + 2*x",
    x_range=(-1, 4),
    show_function_input=True   # text box to change the function
)
plt.show()

Shows f(x) and f'(x). Drag the x slider to move the tangent line.

Calculus — Integral Visualizer

calc.integral_visualizer(
    func_str="x**2 - 4",
    x_range=(-4, 4),
    integration_range=(-2, 3)
)
plt.show()

Sliders a and b adjust the integration bounds. The exact symbolic result (via SymPy) is shown in the title.

General — Multi-Function Plotter

from mathviz import MathViz

core = MathViz()
core.multi_function_plotter(
    functions=["x**2", "sin(x)", "cos(x)", "2*x - 1"],
    x_range=(-5, 5)
)
plt.show()

Each function gets its own labeled text box. Hover tooltips show exact values.

General — Parametric Curves

import numpy as np

core.parametric_plotter(
    x_func="sin(3*t)",
    y_func="sin(2*t)",
    t_range=(0, 2 * np.pi)
)
plt.show()

General — Function Explorer

core.function_explorer(
    initial_func="x**4 - 2*x**2 + 1",
    x_range=(-3, 3),
    auto_detect_features=True
)
plt.show()

Automatically marks roots and critical points.

Linear Algebra — Eigenvector Discovery Mode

from mathviz import LinAlgVisualizer

linalg = LinAlgVisualizer()
linalg.eigenvector_discovery_mode(
    initial_matrix=[[2, 1], [1, 2]]  # symmetric 2×2 matrix
)
plt.show()

Watch the unit circle transform into an ellipse under the matrix transformation. The eigenvectors are highlighted in red when discovered. Supports complex eigenvalues with auto-detection and proper coloring.

Statistics — Hypothesis Testing & Power Analysis

from mathviz import StatsVisualizer

stats = StatsVisualizer()
stats.hypothesis_tester(
    n_range=(10, 500),          # sample size slider
    effect_range=(0, 3),        # Cohen's d slider
    alpha_range=(0.01, 0.2)     # significance level slider
)
plt.show()

Explore Type-I error (α, red shading), Type-II error (β, purple shading), and statistical power (1 - β) interactively. Sliders show live updates of p-values and error rates.

Statistics — Bayesian Updating

stats.bayesian_updater(
    prior_alpha=2,      # Beta prior α
    prior_beta=2,       # Beta prior β
    max_flips=200       # max number of coin flips
)
plt.show()

Visualize prior, likelihood, and posterior distributions as Beta PDFs. Input data (successes/trials) and watch the posterior update in real-time. Shows numerical stability via lgamma-based computation.

Series — Taylor Polynomial "Unwrapper"

from mathviz import SeriesVisualizer

series = SeriesVisualizer()
series.taylor_visualizer(
    initial_func="sin(x)",
    x_range=(-10, 10),
    max_degree=15
)
plt.show()

Drag the degree slider n from 1 upward and watch the red dashed polynomial mold itself onto the black target curve. Drag the center slider a to move the anchor point of the approximation across the function. When the estimated radius of convergence is finite (e.g. for log(1+x) or 1/(1-x)), the region beyond it is shaded red so you can see exactly where the approximation explodes.

Series — Fourier Epicycle Engine

series.fourier_epicycles(
    wave="square",        # 'square', 'sawtooth', 'triangle', or a custom expr in t
    n_harmonics=10,       # initial number of rotating circles
    max_harmonics=50      # slider ceiling
)
plt.show()

Split-screen animation: the left panel shows a chain of rotating circles (radius = Fourier coefficient magnitude, one per harmonic), and the right panel traces the wave their sum produces in real time. Increase N on the slider to add smaller circles and watch the harsh corners of the square wave sharpen. Play/Pause and Reset buttons control the animation; submitting a new wave in the text box (built-in name or any SymPy expression in t) rebuilds everything live.

DiffEq — Interactive Slope Field Dropper

from mathviz import DiffEqVisualizer

diffeq = DiffEqVisualizer()
diffeq.slope_field_dropper(
    ode_str="x - y",     # right-hand side of dy/dx = f(x, y)
    x_range=(-5, 5),
    y_range=(-5, 5)
)
plt.show()

The canvas shows the static slope field for dy/dx = f(x, y). Click anywhere to drop a particle: the library runs a Runge-Kutta (RK4) integration through that point, both forward and backward, and draws the resulting solution curve. Click several spots to build up a family of solutions; use Clear Drops to start over.

DiffEq — Predator-Prey Phase Plane (Lotka-Volterra)

diffeq.lotka_volterra_phase_plane(
    alpha=1.1, beta=0.4, gamma=0.4, delta=0.1,
    initial=(10.0, 5.0)
)
plt.show()

Top panel plots both populations over time; bottom panel is the phase plane. Sliders control the four system parameters live. Drag the diamond marker anywhere in the phase plane (or click a new spot) to set a different initial condition and watch a new cyclical orbit draw itself around the equilibrium point.

Save a Figure

viz = AlgebraVisualizer()
fig = viz.quadratic_explorer()
viz.save_figure("output.png", dpi=300)

Jupyter Notebook Usage

Important — Text Input in Notebooks

Matplotlib's native TextBox widget works perfectly in standalone Python scripts. Inside a Jupyter Notebook, the %matplotlib widget (ipympl) backend often fails to trap letter keypresses before Jupyter's own keyboard shortcuts intercept them (x = cut cell, d = delete, b = insert below, etc.).

Rule of thumb:

Environment Use
Standalone script / demo.py MathViz, AlgebraVisualizer, CalculusVisualizer
Jupyter — sliders only JupyterMathViz
Jupyter — text input needed JupyterSimpleMathViz ✅

Uses native ipywidgets.Text boxes — all keystrokes are trapped correctly.

%matplotlib inline   # or widget — both work
from mathviz import JupyterSimpleMathViz

viz = JupyterSimpleMathViz()

viz.interactive_function_plotter(initial_func="x**2")  # type sin(x), x**3, etc.
viz.interactive_derivative(initial_func="x**3")
viz.interactive_integral(initial_func="sin(x)")
viz.interactive_quadratic()
viz.interactive_parametric()

# v0.3.0+ — Jupyter-safe Series/DiffEq tools (use these instead of
# SeriesVisualizer/DiffEqVisualizer directly whenever you plan to type into
# a text box live in the notebook):
viz.interactive_taylor(initial_func="log(1+x)", max_degree=12)
viz.interactive_fourier_epicycles(wave="square", n_harmonics=10)
viz.interactive_slope_field(ode_str="x - y")

# Save the latest rendered plot even if toolbar save icon is missing:
viz.save_last_figure("my_plot.png", dpi=300)

Note: interactive_fourier_epicycles swaps the matplotlib-widget version's Play/Pause animation for a Time (t) slider (drag it to scrub through one period), and interactive_slope_field swaps clicking on the canvas for x0/y0 sliders — both are the safe, ipywidgets-only equivalents of the click/animate interactions.

Saving in VS Code Notebooks / Colab

Some notebook frontends hide or limit the matplotlib toolbar save icon. This is frontend behavior, not a MathViz failure.

  • For MathViz, AlgebraVisualizer, CalculusVisualizer: use viz.save_figure(...)
  • For JupyterSimpleMathViz: use viz.save_last_figure(...)
from mathviz import AlgebraVisualizer, JupyterSimpleMathViz

# Core visualizer save
core_viz = AlgebraVisualizer()
core_viz.quadratic_explorer()
core_viz.save_figure("quadratic.png", dpi=300)

# JupyterSimple save
simple_viz = JupyterSimpleMathViz()
simple_viz.interactive_function_plotter("sin(x)")
simple_viz.save_last_figure("function.png", dpi=300)

JupyterMathViz (slider-only fallback)

from mathviz import JupyterMathViz

jv = JupyterMathViz()
jv.interactive_quadratic()

from mathviz import ExampleGallery

gallery = ExampleGallery()

gallery.algebra_examples()    # quadratic & polynomial demos
gallery.calculus_examples()   # derivative & integral demos
gallery.advanced_examples()   # parametric, multi-function demos

# List all available examples
for category, items in gallery.get_example_list().items():
    print(f"{category}: {items}")

Supported Function Syntax

All text inputs accept standard SymPy / NumPy expressions:

Math Python syntax
x² x**2
sin x sin(x)
eˣ exp(x)
ln x log(x)
√x sqrt(x)
|x| Abs(x)
π pi

Project Structure

mathviz/
├── __init__.py           # Public API, get_info(), print_info(), quick_start()
├── core.py               # MathViz base class — all general-purpose tools
├── concepts.py           # AlgebraVisualizer, CalculusVisualizer, LinAlgVisualizer, StatsVisualizer
├── series.py             # SeriesVisualizer — Taylor unwrapper, Fourier epicycles (v0.3.0+)
├── diffeq.py             # DiffEqVisualizer — slope field dropper, Lotka-Volterra phase plane (v0.3.0+)
├── widgets.py            # Slider, Button, InputBox wrappers
├── examples.py           # ExampleGallery
├── jupyter_integration.py# JupyterMathViz (ipywidgets.interact, sliders only)
├── jupyter_simple.py     # JupyterSimpleMathViz (ipywidgets.Text, full input)
└── utils.py              # export_to_data_url and helpers

notebooks/
├── getting_started.ipynb            # Full walkthrough — run this first
├── algebra_examples.ipynb
├── calculus_examples.ipynb
├── v3_series_diffeq_examples.ipynb  # Series/DiffEq walkthrough incl. Jupyter-safe tools (v0.3.0+)
└── test_mathviz.ipynb               # Manual integration test notebook

tests/
├── test_core.py          # 45 tests — MathViz base class
├── test_algebra.py       # 38 tests — AlgebraVisualizer
├── test_calculus.py      # 37 tests — CalculusVisualizer
├── test_linalg.py        # 9 tests — LinAlgVisualizer (v0.2.0+)
├── test_stats.py         # 13 tests — StatsVisualizer (v0.2.0+)
├── test_series.py        # 16 tests — SeriesVisualizer (v0.3.0+)
├── test_diffeq.py        # 10 tests — DiffEqVisualizer (v0.3.0+)
├── test_jupyter_simple.py# 17 tests — Jupyter-safe Series/DiffEq wrappers (v0.3.0+)
└── test_integration.py   # 37 tests — package metadata, widgets, utils, gallery

Running Tests

# All tests
pytest tests/ -v

# With coverage
pytest tests/ --cov=mathviz --cov-report=term-missing

# Quick smoke test
pytest test_mathviz.py -v

Current status: 210 tests, 0 failures, 1 skipped (165 core + 22 v0.2.0 features + 43 v0.3.0 features).


Architecture

MathViz (core.py)
├── create_figure() / show() / close() / save_figure()
├── add_slider() / add_button() / add_textbox()
├── function_explorer()
├── multi_function_plotter()
└── parametric_plotter()

AlgebraVisualizer(MathViz)       — concepts.py
├── quadratic_explorer()
└── polynomial_explorer()

CalculusVisualizer(MathViz)      — concepts.py
├── derivative_visualizer()
└── integral_visualizer()

LinAlgVisualizer(MathViz)        — concepts.py (v0.2.0+)
├── space_transformer()
└── eigenvector_discovery_mode()

StatsVisualizer(MathViz)         — concepts.py (v0.2.0+)
├── hypothesis_tester()
└── bayesian_updater()

SeriesVisualizer(MathViz)        — series.py (v0.3.0+)
├── taylor_visualizer()
└── fourier_epicycles()

DiffEqVisualizer(MathViz)        — diffeq.py (v0.3.0+)
├── slope_field_dropper()
└── lotka_volterra_phase_plane()

JupyterSimpleMathViz             — jupyter_simple.py (standalone, no MathViz inheritance)
├── interactive_function_plotter()
├── interactive_derivative()
├── interactive_integral()
├── interactive_quadratic()
└── interactive_parametric()

Key design decisions:

  • All visualizer methods return self.fig — composable and testable
  • Invalid function strings display an error inside the axes; they never raise to the caller
  • Widgets are stored in self.widgets[label] so Python's GC cannot destroy them mid-session
  • mplcursors and ipywidgets are optional — guarded by try/except ImportError
  • SymPy handles symbolic differentiation and integration; lambdify converts to NumPy for plotting

Known Limitations

  • Matplotlib TextBox in Jupyter Notebooks intercepts letter keypresses → use JupyterSimpleMathViz instead
  • JupyterSimpleMathViz redraws the full figure on every widget change (ipywidgets constraint) — hover tooltips not available
  • polynomial_explorer supports degree 2–5 only; degree outside this range raises ValueError
  • Very large x-ranges with discontinuous functions (e.g. tan(x)) may show visual spikes

License

MIT License — see LICENSE for details.


Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Run tests: pytest tests/
  4. Submit a pull request to HORRIDBEAST/MathViz---The-Ultimate-Math-Py-Library

Please ensure all existing tests pass and add tests for new functionality.

Metadata

Release files for mathvizpro 0.3.0

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

Source distribution (sdist)

Source distribution for mathvizpro 0.3.0
File Size Uploaded Provenance Actions
mathvizpro-0.3.0.tar.gz 2.3 MB Without provenance Details for mathvizpro-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mathvizpro 0.3.0
File Interpreter ABI Platform Actions
mathvizpro-0.3.0-py3-none-any.whl Python 3 none any Details for mathvizpro-0.3.0-py3-none-any.whl

Total release size: 2.3 MB

Release files / mathvizpro-0.3.0.tar.gz

Download URL mathvizpro-0.3.0.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
13a0aefccac052f2b304f9a7ac40531965d77b49eff02e9d3711eaa3ba255cbb
BLAKE2b-256 checksum
How to use checksums
98fb3196b23d4b788f9f00183bddaf5299d02dd5b8e039563b9094b8b7a5fbea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / mathvizpro-0.3.0-py3-none-any.whl

Download URL mathvizpro-0.3.0-py3-none-any.whl
Size 44.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e80e346ba0d8b793433cf6984e9f2ef5c14774c9dbb110a319705a08c590c389
BLAKE2b-256 checksum
How to use checksums
a0c5365c4e15efc218bb190fc5002094aae34541466695ca1bc00b28a2c8d099
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for mathvizpro 0.3.0

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.

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