API Workflow
Every plot and chart in Kaxe follows the same four-step pattern.
The four steps
Create a window —
Plot,Bar,Plot3D, or another window class.Add content —
kaxe.Window.add()for plot objects, or chart-specific methods likeBar.add(label, values).Style —
kaxe.Window.theme(),kaxe.AttrMap.style(),kaxe.Window.title(),kaxe.Window.legend().Output —
kaxe.Window.save()orkaxe.Window.show().
import kaxe
plt = kaxe.Plot([-3, 3, -1, 9])
plt.add(kaxe.Function2D(lambda x: x**2))
plt.theme(kaxe.Themes.A4Medium)
plt.style(fontSize=60)
plt.save("parabola.png")
Plots vs charts
Plots display mathematical and geometric objects: functions, points, equations, contours, 3D surfaces, and similar.
Charts display statistical summaries: pie slices, bar groups, box plots, QQ plots.
Both inherit from kaxe.Window, so they share style, theme, save, and show. The difference is how you populate them:
Window type |
Typical constructor |
Add content via |
|---|---|---|
Plot |
|
|
Chart |
|
|
Charts are not passed to Plot.add(). Create a chart window directly:
chart = kaxe.Bar()
chart.add("A", [1, 2, 3])
chart.save("bars.png")
Smart objects vs typed objects
Smart objects adapt to the plot type you add them to:
kaxe.Function— callable for 2D or 3D plotskaxe.Points— x/y or x/y/z data
Use smart objects when the same code should work on both 2D and 3D plots.
Typed objects target a specific dimension:
2D:
kaxe.Function2D,kaxe.Points2D,kaxe.Equation,kaxe.Contour, …3D:
kaxe.Function3D,kaxe.Points3D,kaxe.Mesh, …
Use typed objects when you need explicit control or extra parameters only available on the 2D/3D class.
Window methods reference
Method |
Purpose |
|---|---|
Add a drawable object to a plot |
|
|
Set style attributes ( |
|
Print available style keys |
Apply an A4 page preset from |
|
Scale figure size relative to a LaTeX page |
|
|
Set the plot title (LaTeX math supported) |
|
Configure the legend |
Write PNG or SVG to disk or a buffer |
|
Display in a viewer or Jupyter notebook |
|
Create a magnified inset on a 2D plot |
See also Styling, Legends and Titles, and Recipes.
Themes and LaTeX page sizing
kaxe.Themes provides presets sized for A4 documents:
A4Large,A4Medium,A4Small,A4Slim,A4Mini
plt.theme(kaxe.Themes.A4Medium)
kaxe.Window.adjust() estimates font and figure size for a given fraction of page width:
plt.adjust(0.5) # roughly half an A4 text width
Both methods only change style attributes — they do not resize an already-rendered image.
Plot bounds
Pass [x0, x1, y0, y1] to set the visible data range. Use None for an axis bound to auto-scale from the data:
plt = kaxe.Plot([-5, 5, -1, 10]) # fixed x and y
plt = kaxe.Plot([-40, 30, None, None]) # auto y from data
plt = kaxe.Plot() # auto both axes
Points, pillars, and other data objects contribute their extents automatically.
kaxe.Function2D and kaxe.Function3D also participate: when an axis
is left as None, Kaxe coarse-samples the function and sets the window from the
result. Auto-computed axes get 5% symmetric padding.
import math
import kaxe
plt = kaxe.Plot()
plt.add(kaxe.Function2D(math.sin)) # auto x and y
plt = kaxe.Plot([-5, 5, None, None])
plt.add(kaxe.Function2D(math.sin)) # fixed x, auto y
plt = kaxe.Plot3D()
plt.add(kaxe.Function3D(lambda x, y: math.sin(x) * math.cos(y)))
Override sampling or output intervals on the function itself:
# Sample on [-pi, pi] instead of the default [-10, 10]
kaxe.Function2D(math.sin, domain=(-math.pi, math.pi))
# Pin y while auto-scaling x
kaxe.Function2D(lambda x: x**2, range=(0, 10))
# 3D: explicit xy domain, auto z
kaxe.Function3D(lambda x, y: x + y, domain=(-2, 2, -3, 3))
For unbounded functions (exp, 1/x, sharp asymptotes), set domain and/or
range explicitly, or fix the plot window. Use kaxe.Plot.pad() for extra
margin beyond the built-in 5%.
Polar plots take [r_min, r_max]. 3D plots take [x0, x1, y0, y1, z0, z1].
Log plots use positive bounds on logarithmic axes. For log-log, pass both flags:
plt = kaxe.LogPlot([0.1, 100, 0.1, 1000], firstAxisLog=True, secondAxisLog=True)
Zoom inset
On 2D plots, kaxe.Plot.zoom() returns a linked sub-window. Objects added via zoom.add() appear only in the inset:
import math
plot = kaxe.Plot([0, 4 * math.pi, -1, 1])
plot.add(kaxe.Function2D(math.sin))
zoom = plot.zoom(2.5, 4, -0.4, -0.1, position=(5, -0.5))
zoom.add(kaxe.Points2D([3.2], [-0.2], color=(255, 0, 0, 255)))
See Plots for all zoom() parameters.