DEV Community

Luan Nguyen
Luan Nguyen

Posted on Originally published at nuan2779.github.io

STEM Vector Math Plotter & 24-Asset SVG Diagram Pack

STEM Vector Math Plotter & 24-Asset SVG Diagram Pack

How to Generate Clean, Themeable Math SVGs for Technical Docs Without Matplotlib Bloat

Writing technical documentation, ML engineering blogs, or STEM courseware often hits the same snag: you need crisp, dark-mode-friendly mathematical plots and geometric diagrams, and your options are either screenshotting a desktop window or installing a 300 MB Python plotting stack just to render sin(x) or a normal distribution curve.

Why this problem wastes time

Exporting raster PNGs or default scientific charts creates three recurring bottlenecks for developers and technical writers:

  • Theme mismatch and blurry scaling: Static PNGs look jagged on high-DPI displays and break in dark-mode documentation sites or blueprint slide decks.
  • Uneditable monolithic exports: Standard chart generators dump thousands of ungrouped paths, making it painful to toggle a grid, highlight an asymptote, or move a tangent callout inside Figma or Illustrator.
  • Dependency overhead and broken asymptotes: Pulling matplotlib and numpy into a docs CI pipeline slows builds, while naive curve samplers connect vertical asymptotes (1/x, tan(x), 1/(x^2-1)) with ugly diagonal spikes across the canvas.

Step-by-step workflow

You can generate lightweight, responsive, Figma-layered SVGs directly from mathematical expressions using a pure-math recursive-descent parser and SVG <clipPath> geometry guards:

  1. Parse equations safely without eval: Tokenize and parse arithmetic (+, -, *, /, ^ with right-associative precedence tighter than unary - so -x^2 == -(x^2)), implicit multiplication (2x, 2sin(x), (x+1)(x-1)), constants (pi, e, tau), and functions (sin, cos, tan, exp, ln, log10, sqrt, abs, floor, ceil).
  2. Handle domain gaps and discontinuities cleanly: Skip NaN or out-of-domain points (such as negative inputs to sqrt(x) or ln(x)) and start a fresh M subpath when the domain resumes. Split subpaths automatically whenever abs(y - prev_y) jumps across a vertical pole like 1/(x^2 - 1).
  3. Structure output into named Figma <g> layers: Separate bg-layer, grid-layer, axes-layer, shaded-layer, curve-layer (wrapped in <clipPath>), and annotations-layer inside a responsive viewBox="0 0 800 520" SVG.
  4. Render from the command line with zero external dependencies: run python generate_math_svg.py plot --mode explicit --expr "1/(x^2 - 1)" --xmin -4 --xmax 4 --ymin -4 --ymax 4 --theme dark --accent "#38bdf8" --auto-asymptotes -o rational-plot.svg to generate a clean dark-theme SVG with automatic discontinuity splitting and dashed asymptote lines.

Automating it in seconds

If you want to preview equations interactively in your browser before automating full asset sets, try the live STEM Vector Math Plotter in index.html:

  • Switch between Explicit (y = f(x)), Parametric ((x(t), y(t))), and Polar (r(theta)) modes.
  • Customize xmin/xmax, light/dark/blueprint themes, accent hex color, stroke width, grid visibility, and optional tangent line overlays (Tangent @ x₀).
  • Inspect 6 free preview samples (4 annotated STEM diagrams and 2 seamless patterns), copy clean SVG markup with one click, or download a preview .svg.

When you are ready to skip drawing diagrams from scratch, the $7.00 Pro 24-Asset Pack on Polar.sh includes:

  • 16 multi-layer annotated STEM SVG diagrams (diagrams/*.svg) covering Unit Circle projections, Normal Distribution ±1σ/±2σ/±3σ bands, Midpoint Riemann Sums, Taylor Series (sin(x)), Damped Harmonic Oscillator, Fourier Square Wave, ML Activations (Sigmoid/Tanh/ReLU/Softplus), Gradient Descent Contours, Conic Sections, Rational Asymptotes, Lissajous 3:4, Polar Rose & Cardioid, 2D Vector Field Flow, PID Step Response, Cubic Bézier Control Polygon, and Logarithmic Golden Spiral.
  • 8 seamless tileable <pattern> SVGs (patterns/*.svg) for Blueprint Grids, Isometric Dots, Polar Radar, Log Graph Paper, Hex Mesh, Trig Waves, Crosshairs, and Chalkboard Dots.
  • Offline batch CLI (generate_math_svg.py + presets.json) so you can regenerate all 24 assets in light, dark, or blueprint themes in one command: python generate_math_svg.py batch --presets presets.json --theme blueprint --out-dir ./blueprint-pack.

Try It & Download

Top comments (0)