Utilities
Helper functions and classes that are not plot windows or drawable objects.
Number formatting
- kaxe.koundTeX(num: float) str
Format a number for axis labels using LaTeX-style notation.
Small integers are returned as plain numbers. Very small or very large values use scientific notation. Thousands separators use
\smallSpace.- Parameters:
num (float) – Numeric value to format.
- Returns:
LaTeX math string, e.g.
"$5*10^{-4}$"or"$314$".- Return type:
str
Examples
>>> koundTeX(0.005) '$5.0*10^{-3}$' >>> koundTeX(314) '$314$'
Global settings
- kaxe.setSetting(**kwargs)
Set global Kaxe runtime settings.
- Parameters:
**kwargs –
Supported keys:
- removeInfobool
When
True, suppress progress bars and bake timing logs. Useful in notebooks and batch scripts.- jupyterLoadingThresholdfloat
Seconds before a progress bar appears in Jupyter (default 1.0). Fast plots stay quiet.
- jupyterDisplayWidthint
Width in pixels for inline notebook display (default 800).
Examples
>>> setSetting(removeInfo=True)
Note
Currently supported keys: removeInfo (bool) — suppress progress bars and bake timing logs.
Colors
- kaxe.to_rgba(color) tuple[int, int, int, int]
Normalize a color to an RGBA tuple with channels in 0–255.
- Parameters:
color (str, sequence, or numpy array) – Hex string (e.g.
"#FF5154"), named color (e.g."red"), or RGB/RGBA sequence.- Returns:
(r, g, b, a)with integer channels 0–255.- Return type:
tuple[int, int, int, int]
- Raises:
TypeError – If
coloris aColormapinstance.ValueError – If the color format is not recognized.
- kaxe.setDefaultColors(colorList: list)
Set the global default colors for all plots
- Parameters:
colorList (list) – A list of colors to be set as the default colors. Entries may be RGBA tuples or hex/named color strings (see
kaxe.to_rgba()).
Notes
This function sets the global variable colors to the provided list of colors.
- kaxe.resetColor() None
Resets the global color number to its initial state. This function sets the global variable colorNum to -1, effectively resetting any color-related state that depends on this variable.
Note
This resets all plot color progress
- kaxe.getRandomColor() tuple
Return the next color from Kaxe’s default color cycle.
Colors rotate through the built-in palette. Call
resetColor()to restart the cycle from the first color.- Returns:
RGBA color tuple, e.g.
(222, 107, 72, 255).- Return type:
tuple
Colormaps
- class kaxe.Colormap(colorGradientSteps: list | tuple)
A class to represent a colormap that interpolates colors from a gradient.
- Parameters:
colorGradientSteps (Union[list, tuple]) – A list or tuple of colors representing the gradient steps. Colors can be in hexadecimal string format or RGBA arrays.
- getColor(value: int | float, start: int | float, end: int | float)
Get the interpolated color from the color gradient steps based on the input value.
- Parameters:
value (Union[int, float]) – The value for which the color needs to be determined.
start (Union[int, float]) – The start value of the range.
end (Union[int, float]) – The end value of the range.
- Returns:
The interpolated color from the color gradient steps.
- Return type:
color
Notes
If value is less than start, the first color in the gradient steps is returned.
If value is greater than end, the last color in the gradient steps is returned.
The interpolation is linear between the two nearest colors in the gradient steps.
Examples
>>> cmap.getColor(3.5, 0, 10) (125, 215, 51, 255)
- class kaxe.Colormaps
A collection of predefined colormaps for various color schemes.
- red
A single color colormap with the color red.
- Type:
- class kaxe.SingleColormap(color, spread=0.3, total=10)
SingleColormap is a subclass of Colormap that generates a colormap based on a single color.
- Parameters:
color (str or list or tuple) – The base color for the colormap. If a string is provided, it should be a hex color code. If a list or tuple is provided, it should contain RGB or RGBA values.
spread (float, optional) – A float larger than 1 describing the spread of the colors Default is [0.3, 0.7].
total (int, optional) – The total colors in the colormap
See also
Symbols
- class kaxe.symbol
Themes
- class kaxe.Themes
A class used to represent different themes for plotting.
- A4Large
A dictionary containing settings for a large A4 plot.
- Type:
dict
- A4Medium
A dictionary containing settings for a medium A4 plot.
- Type:
dict
- A4Small
A dictionary containing settings for a small A4 plot.
- Type:
dict
- A4Slim
A dictionary containing settings for a slim A4 plot.
- Type:
dict
- A4Mini
A dictionary containing settings for a mini A4 plot.
- Type:
dict
Axis
The axis object used by most plots exposes additional attributes and methods:
- class kaxe.Axis(directionVector: tuple, titleNormal: tuple, numberOnAxisGoalReference: str)
Axis is a class for creating and managing axes in a plot.
- add(text: str, pos: int | float, showLine: bool = True)
Add markers to the axis.
- Parameters:
text (str) – The text label for the marker.
pos (int | float) – The position of the marker on the axis.
showLine (bool, optional) – Whether to show a line for the marker (default is True).
Ghost legends
Add legend entries that are not tied to a specific plotted object:
- class kaxe.GhostLegend(text: str, color: tuple, symbol: str)
Adds a legend
- Parameters:
text (str) – The text to be displayed in the legend.
symbol (symbols) – The symbol to be used in the legend.
color (tuple) – The color to be used for the legend text. If not provided, the default color will be used.
Excel data loader
Load a rectangular range from an .xlsx workbook. Column indices are 1-based (Excel convention):
import kaxe
# Sheet "Results", columns A–B, rows 2 through last row
table = kaxe.data.loadExcel("results.xlsx", "Results", top=(1, 2), bottom=(2, -1))
x = [row[0] for row in table]
y = [row[1] for row in table]
plt = kaxe.Plot()
plt.add(kaxe.Points2D(x, y))
Set flip=True to transpose rows and columns. See Recipes for a full example.
- data.loadExcel(sheet: str, top: tuple, bottom: tuple, flip: bool = False)
Load data from an Excel sheet within a specified range.
- Parameters:
fname (str) – The filename of the Excel workbook.
sheet (str) – The name of the sheet to load data from.
top (tuple) – A tuple (column, row) representing the top-left corner of the range.
bottom (tuple) – A tuple (column, row) representing the bottom-right corner of the range. If the row is -1, it will be set to the maximum row of the sheet.
flip (bool, optional) – If True, the data will be transposed (flipped). Defaults to False.
- Returns:
A 2D list containing the data from the specified range in the Excel sheet.
- Return type:
list