Function Graph Generator

Plot common functions and custom expressions in 2D, with configurable ranges, curve color, line width, grid, and axes, plus SVG and PNG export.

FreeOnline Tool
Loading…

How to Use

The default is f(x) = sin(x) with X from -10 to 10 and Y from -5 to 5. Any change redraws immediately.

  1. Choose a preset from the f(x) selector: sin, cos, tan, ln, log₁₀, e^x, √x, |x|, xⁿ, x, x², x³, or Custom Function.
  2. For presets, set coefficient A and offset B to plot y = A·f(x) + B; the power function also takes an exponent n. For a custom function, the expression is the complete f(x) and the coefficient/offset fields are ignored.
  3. Set the X and Y minimum and maximum values. Both minimums must be less than their maximums. You can also choose a curve color, a line width from 1 to 10, and toggle the grid and axes.
  4. Custom expressions support + - * / % ^, parentheses, and implicit multiplication such as 2x, 2sin(x), or (x+1)(x-1). Functions include sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, ln, log, log10, log2, sqrt, cbrt, abs, exp, pow, min, max, hypot, floor, ceil, round, trunc, and sign; constants are pi, π, and e. Trigonometric functions use radians.
  5. The quick chips switch to sin, cos, tan, x², x³, √x, ln, or e^x with suitable display ranges.
  6. The toolbar provides Redraw, Zoom in, Zoom out, Reset, Copy SVG, Download SVG, and Download PNG. “Load sample” plots 2sin(x)+1 and resets the styling.

Features

  • Presets and custom expressions: 12 preset functions cover trigonometric, logarithmic, exponential, root, absolute-value, and power functions; custom expressions plot any single-variable function.
  • Coefficient and offset: presets support y = A·f(x) + B for amplitude scaling, vertical shifts, and reflection. A custom expression is used directly as f(x).
  • Free viewport: set X and Y bounds independently and zoom around the view center. Zoom is limited to spans from 1e-6 to 1e9.
  • Styling: choose the curve color, a line width of 1–10, and toggle grid and axes independently. Tick spacing uses nice 1/2/5×10ⁿ steps.
  • Safe expression parsing: a built-in tokenizer/parser is used instead of eval or new Function, with implicit multiplication, math functions, and the constants pi, π, and e.
  • Export: copy the current graph as SVG text, download an SVG file, or download a PNG. SVG export follows the current grid, axes, color, and line-width settings.

Use Cases

Classroom function demonstrations
Plot sin, cos, tan, x², x³, ln, and e^x with grid, axes, and zoom to show periodicity, monotonicity, and asymptotes.
Check a custom formula
Paste a formula from an experiment or codebase to look for domain breaks, unexpected oscillation, or magnitude problems.
Slides and vector illustrations
Set the curve color, line width, and range, then copy the SVG for web pages, slides, or vector layouts without raster blur.
Inspect engineering function shapes
Plot scaled and shifted functions to see their value range and trend over a target interval when choosing initial parameters.

FAQ

Does a custom function use the coefficient A and offset B?
No. A custom expression is plotted as the complete f(x); A and B apply only to presets. To scale or shift a custom function, write the factors into the expression, for example 2*sin(x)+1.
Which functions, constants, and operators are supported?
Operators +, -, *, /, %, ^, parentheses, and implicit multiplication such as 2x, 2sin(x), and (x+1)(x-1). Functions: sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, ln, log (base 10), log10, log2, sqrt, cbrt, abs, exp, pow, min, max, hypot, floor, ceil, round, trunc, sign. Constants: pi, π, e. Trigonometric functions use radians.
Why is the graph blank or only partly drawn?
Common causes are an X or Y minimum that is not less than its maximum; a function undefined in the range, such as ln(x) or √x with negative values or a negative base with a non-integer exponent; or a curve completely outside the Y range. The tool reports an invalid range or that no valid points are visible.
Why is tan(x) drawn as separate segments?
tan is undefined at π/2 + kπ, so those samples are invalid and the path is broken to avoid drawing a false vertical line at the asymptote. This is expected behavior, not a rendering error.
Are there limits on zooming?
Yes. Zoom in and out around the current view center, and the X and Y spans are clamped between 1e-6 and 1e9 to prevent collapsing to zero or becoming numerically meaningless. You can also edit the X and Y bounds directly.
Which export formats are available?
You can copy SVG text, download function-graph.svg, or download the current canvas as function-graph.png. The SVG includes the background, grid, axes, curve, and expression title and respects the color and line-width settings.