Skip to main content

Convert mathematical equations into graph structures for visualization

Project description

numgraph ๐Ÿ”ขโžก๏ธ๐Ÿ“Š

PyPI version Python 3.8+ License: MIT CI codecov

A Python library that converts mathematical equations, functions, or datasets into graph/network structures for visualization and analysis.

๐ŸŽฏ What is numgraph?

numgraph turns mathematical relationships into nodes and edges, then visualizes them. This helps users see how variables and operations interact โ€” perfect for:

  • ๐Ÿ“š Students learning algebra/calculus
  • ๐Ÿ”ฌ Data scientists analyzing feature dependencies
  • ๐Ÿงช Researchers visualizing formulas or constraints

๐Ÿš€ Quick Start

Installation

Install from PyPI (once published):

pip install numgraph

Or install from source:

git clone https://github.com/ayushmishra/numgraph.git
cd numgraph
pip install -e .

For development:

pip install -e ".[dev]"

Basic Usage

from numgraph import make_graph

# Parse and visualize an equation
make_graph("x**2 + y**2 = 25", visualize=True)

# Create a function graph
make_graph("y = x**2 - 4*x + 3", func_range=(-10, 10), visualize=True)

๐Ÿ“ฆ Features

โœ… Phase 1: Core Functionality (MVP)

  • Parse mathematical equations using sympy
  • Build graph structures with networkx
  • Visualize using matplotlib and pyvis
  • Export graphs to various formats

๐Ÿ”ฎ Phase 2: Function Graphs

  • Plot functional relationships
  • Show variable dependency graphs
  • Evaluate functions over ranges

๐Ÿ“Š Phase 3: Dataset Integration (Coming Soon)

  • Build correlation graphs from DataFrames
  • Analyze feature relationships
  • Threshold-based edge creation

๐Ÿง  Phase 4: Advanced Features (Planned)

  • Auto-detect independent/dependent variables
  • Bipartite graph visualization
  • Export to .graphml, .png, etc.
  • AI-based function simplification

๐Ÿ“– Examples

Circle Equation

from numgraph import make_graph

# Visualize the circle equation
make_graph("x**2 + y**2 = 25", visualize=True, save_path="circle.html")

Quadratic Function

from numgraph import make_graph

# Plot a parabola
make_graph("y = x**2 - 4*x + 3", func_range=(-2, 6), visualize=True)

Custom Graph Analysis

from numgraph.parser import EquationParser
from numgraph.graph_builder import GraphBuilder
from numgraph.visualizer import Visualizer

# Parse equation
parser = EquationParser("x**2 + 2*x*y + y**2 = 16")
nodes, edges = parser.parse()

# Build graph
builder = GraphBuilder(nodes, edges)
graph = builder.build()

# Visualize
viz = Visualizer(graph)
viz.show_interactive()  # Interactive HTML visualization
viz.show_static()       # Static matplotlib plot

๐Ÿ› ๏ธ API Reference

make_graph(equation, visualize=False, func_range=None, save_path=None)

Main function to create and optionally visualize equation graphs.

Parameters:

  • equation (str): Mathematical equation or function
  • visualize (bool): Whether to show visualization
  • func_range (tuple): Range for function evaluation (min, max)
  • save_path (str): Path to save interactive HTML visualization

Returns:

  • networkx.Graph: Graph representation of the equation

๐Ÿ—๏ธ Project Structure

numgraph/
โ”‚
โ”œโ”€โ”€ numgraph/
โ”‚   โ”œโ”€โ”€ __init__.py         # Main API
โ”‚   โ”œโ”€โ”€ parser.py           # Equation parsing logic
โ”‚   โ”œโ”€โ”€ graph_builder.py    # NetworkX graph creation
โ”‚   โ”œโ”€โ”€ visualizer.py       # Matplotlib/Pyvis visualization
โ”‚   โ””โ”€โ”€ dataset.py          # Dataset โ†’ graph (future)
โ”‚
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ circle_equation.py
โ”‚   โ”œโ”€โ”€ quadratic_function.py
โ”‚   โ””โ”€โ”€ custom_analysis.py
โ”‚
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_parser.py
โ”‚   โ”œโ”€โ”€ test_graph_builder.py
โ”‚   โ””โ”€โ”€ test_visualizer.py
โ”‚
โ”œโ”€โ”€ setup.py
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ requirements.txt

๐Ÿงช Testing

# Run all tests
python -m pytest tests/

# Run specific test
python -m pytest tests/test_parser.py -v

๐Ÿ“„ License

MIT License - feel free to use this project however you'd like!

๐Ÿค Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

๐Ÿ“ Publishing

To publish this package to PyPI for others to use, see PUBLISHING.md for detailed instructions.

๐Ÿ“‹ Changelog

See CHANGELOG.md for version history and release notes.

๐Ÿ”— Tech Stack

  • sympy โ†’ Symbolic mathematics and parsing
  • networkx โ†’ Graph creation and analysis
  • pyvis โ†’ Interactive network visualization
  • matplotlib โ†’ Static plotting
  • numpy โ†’ Numerical computations

๐ŸŽ“ Use Cases

For Students

  • Visualize how equations are structured
  • Understand operator precedence
  • See variable relationships clearly

For Educators

  • Create interactive math visualizations
  • Demonstrate equation parsing
  • Teaching tool for graph theory

For Researchers

  • Analyze mathematical formula structure
  • Study equation complexity
  • Visualize algorithm dependencies

For Developers

  • Parse mathematical expressions
  • Build equation-based applications
  • Create mathematical documentation

๐Ÿ“ฎ Contact

For questions or suggestions, please open an issue on GitHub.

โญ Show Your Support

If you find numgraph helpful, please give it a star on GitHub!

๐Ÿ™ Acknowledgments

Built with these amazing libraries:


Made with โค๏ธ for math and graph enthusiasts!

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

numgraph_equation-0.1.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

numgraph_equation-0.1.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file numgraph_equation-0.1.0.tar.gz.

File metadata

  • Download URL: numgraph_equation-0.1.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for numgraph_equation-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f79c572d58d449ca549c213b128e13f0697e6da4a2c3004259d3ea1edbc14cba
MD5 18957105ab7d1cd62be46222e15299f5
BLAKE2b-256 5ebac888adb349a2a8dd38d6c07e3b2f5bd043457c6d1fc92f620dc78766858e

See more details on using hashes here.

File details

Details for the file numgraph_equation-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for numgraph_equation-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0372da9622b2e86ee6074af136f9f6e757c67bea0260d6a2d04b47ce5f4489c
MD5 8a4a5f79e3c43c2d7f9a38e7df1d1d41
BLAKE2b-256 b3b41b9a0722087225630ef4335c25655f9dde6c4c8c3f37f7cfba4d5d29d10c

See more details on using hashes here.

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