GraphAPI

Generate beautiful plots of mathematical equations with ease

Overview

This API allows user to plot math equations encoded with LaTex. It can generate plots from custom LaTeX equations, create random equations for different categories/types of mathematical functions and manage cache of previously generated graphs.

Base URL

https://api.ansonlai.website

Endpoints

1. Plot Custom Equation

Generate a plot from a userprovided LaTeX equation.

Endpoint:

/plot

Method:

GET

Parameters:

Parameter Type Required Default Description
equation string Yes - LaTeX formatted mathematical equation
x_scale int No 20 Width of the x-axis range (-x_scale/2 to x_scale/2)
y_scale int No 20 Height of the y-axis range (-y_scale/2 to y_scale/2)
data_points int No 1000 Number of data points for plotting. Higher values generate smoother curves but increase processing time.

Response:

Success: PNG image of the plotted equation

Error: 400 status code with error message

2. Generate Random Equation

Generate and plot a random equation from a specified category.

Endpoint:

/random

Method:

GET

Parameters:

Parameter Type Required Default Description
category string Yes - Mathematical category for the random equation
x_scale int No 20 Width of the x-axis range
y_scale int No 20 Height of the y-axis range
data_points int No 1000 Number of data points for plotting. Higher values generate smoother curves but increase processing time.

Valid Categories:

  • sqrt - Square root functions
  • polynomial - Polynomial functions
  • linear - Linear functions
  • trigonometry - Trigonometric functions
  • exponential - Exponential functions
  • logarithm - Logarithmic functions
  • reciprocal - Reciprocal functions

Response:

Success: PNG image of the randomly generated and plotted equation

Error: 400 status code with error message

3. Get Random Cached Graph

Retrieve a random graph from the cache of previously generated plots.

Endpoint:

/cached

Method:

GET

Parameters:

None

Response:

Success: PNG image of a randomly selected cached graph

Note: If the cache is empty, a placeholder image is returned.

4. Clear Cache

Clear all cached graphs.

Endpoint:

/cache

Method:

POST

Parameters:

None

Response:

Success: JSON response with success message

{
  "status": "success",
  "message": "Cache cleared successfully"
}

5. Get Cache Information

Retrieve information about the current cache state.

Endpoint:

/cache/info

Method:

GET

Parameters:

None

Response:

Success: JSON with cache information

{
    "cache_size": 3,
    "graphs": [
        {
        "category": "polynomial",
        "equation": "x^{2}+x^{2}+x^{1}+x^{4}",
        "expires_at": 1742083607.9325397,
        "expires_in": 4.99,
        "id": "88040200",
        "timestamp": 1742065607.9325397
        },
        {
        "category": "trigonometry",
        "equation": "\\frac{-3}{x}\\cdot\\sinh(-1\\cdot x)",
        "expires_at": 1742083613.8341134,
        "expires_in": 5,
        "id": "37389279",
        "timestamp": 1742065613.8341134
        },
        {
        "category": "logarithm",
        "equation": "-0.2\\cdot\\ln(0.0\\cdot(x--2.3))+0.7",
        "expires_at": 1742083621.838154,
        "expires_in": 5,
        "id": "09901580",
        "timestamp": 1742065621.838154
        }
    ],
    "max_cache_size": 50
  ]
}

6. System Health Information

Retrieve current system health metrics including CPU and memory usage.

Endpoint:

/systemhealth

Method:

GET

Parameters:

None

Response:

Success: JSON with system health information

{
  "cpu_usage_percent": 1.0,
  "current_timestamp": 1741618728.4574647,
  "previous_health_check_timestamp": 1741618551.2184849,
  "ram_usage": {
    "percent": 61.5,
    "total_bytes": 1017094144,
    "total_readable": "969.98 MB",
    "used_bytes": 482713600,
    "used_readable": "460.35 MB"
  }
}

Interactive Examples

Plot Custom Equation

Enter a LaTeX formatted equation to see the plotted result.

Higher data point values generate smoother curves but increase processing time.

API Request:

https://api.ansonlai.website/plot?equation=x%5E2%20%2B%205*x%20%2B%206&x_scale=20&y_scale=20&data_points=1000

Result:

Plot will appear here

Random Equation Generator

Select a category to generate a random equation plot.

Higher data point values generate smoother curves but increase processing time.

API Request:

https://api.ansonlai.website/random?category=polynomial&x_scale=20&y_scale=20

Result:

Plot will appear here

Cache Operations

View and manage the cache of previously generated plots.

API Request:

https://api.ansonlai.website/cached

Result:

Result will appear here

Images in cache are only saved for 5 hours from the time of generation.

System Health Monitoring

View current system resource usage to monitor API performance.

API Request:

https://api.ansonlai.website/systemhealth

Result:

System health information will appear here

LaTeX Equation Support

The API supports various LaTeX mathematical notations:

Operation LaTeX Syntax Description
Basic operations +, -, *, /, ^{} Addition, subtraction, multiplication, division, exponentiation
Fractions \frac{numerator}{denominator} Creates a fraction with the specified numerator and denominator
Square roots \sqrt{content} Calculates the square root of the content
Trigonometric functions \sin, \cos, \tan, \arcsin, \arccos, \arctan Standard trigonometric functions
Hyperbolic functions \sinh, \cosh, \tanh Hyperbolic sine, cosine, and tangent
Logarithmic and exponential \exp, \log, \ln Exponential function, logarithm base 10, natural logarithm
Constants \pi Mathematical constant π

Important Note on URL Encoding

LaTeX equations must be properly URL-encoded to be used in API requests. Special characters like backslashes require double escaping (once for LaTeX and once for URL encoding).

Example: \frac{1}{x} becomes %5C%5Cfrac%7B1%7D%7Bx%7D in the URL.

The examples on this page automatically handle the URL encoding for you.