Welcome to fxutil’s documentation!¶
- fxutil.in_ipython_session()¶
Determine if we are running inside an IPython session (e.g., Jupyter Notebook or Jupyter Lab).
- Return type:
bool
- class fxutil.SaveFigure(plot_dir=None, suffix='', output_dpi=250, display_dpi=96, output_transparency=True, make_tex_safe=True, interactive_mode='dark', use_styles=None, filetypes=None, name_str_space_replacement_char='-', width=None, left=0, bottom=0, right=1, top=1, w_pad=4, h_pad=4, wspace=0.02, hspace=0.02, subfolder_per_filetype=False)¶
Bases:
objectA class to save figures in different styles and formats.
- Parameters:
plot_dir (str | Path)
suffix (str)
output_dpi (int)
display_dpi (int)
output_transparency (bool)
make_tex_safe (bool)
interactive_mode (str | None)
use_styles (list[str] | None)
filetypes (Annotated[str | Iterable[str], _CombiTag] | None)
name_str_space_replacement_char (str)
width (float)
- figax(n_panels=None, *, n_rows=None, n_cols=None, left=None, right=None, top=None, bottom=None, wspace=None, hspace=None, width_ratios=None, height_ratios=None, panel_labels=None, width=None, height=None)¶
Create a figure and axes.
- Parameters:
n_panels – Number of panels to create
n_rows (
int|None) – Number of rows to squeeze the panels inton_cols (
int|None) – Number of columns to squeeze the panels intowidth_ratios (
Sequence[float])height_ratios (
Sequence[float])panel_labels (
Optional[bool])width
height
- Returns:
fig – Figure
axs – A single axes or a tuple of multiple axes
- property output_dir¶
- static register_contrast_color(style_name)¶
Register the “contrast” and “acontrast” colors in matplotlib’s color map.
- Parameters:
style_name (
str) – The style name, either “light” or “dark”.
-
styles:
dict[str,list[str]] = {'dark': ['dark_background', 'fxutil.mplstyles.tex', 'fxutil.mplstyles.dark'], 'light': ['default', 'fxutil.mplstyles.tex', 'fxutil.mplstyles.light']}¶
- fxutil.evf(S, f, **kwargs)¶
Use like ax.plot(*evf(np.r_[0:1:50j], lambda x, c: x ** 2 + c, c=5))
- Parameters:
S – Space
f – function
**kwargs – Additional function args
- fxutil.figax(figsize=(4, 3), dpi=130, **kwargs)¶
Convenience function to create matplotlib figure and axis objects with the given parameters.
- Parameters:
figsize (
tuple[float,float]) – Figure size in inches (width, height).dpi (
int) – Resolution of the figure (if rasterized output).kwargs – Additional arguments passed to plt.subplots.
- Return type:
fig, ax
- fxutil.pad_range(left, right, pad=0.03, log=False)¶
Pad plots ranges to achieve equal-distance padding on both sides.
Use like
- Parameters:
left – Left unpadded bound
right – Right unpadded bound
pad – Padding to be added on both sides as a fraction.
log – If True, assume log scale
- Returns:
Tuple of left and right bounds
- Return type:
bounds
- fxutil.easy_prop_cycle(ax, N=10, cmap='cividis', markers=None)¶
- fxutil.fmt_bytes(s)¶
- fxutil.described_size(desc, obj)¶
Use like
`py >>> print(described_size("my huge-ass object's size: ", my_huge_ass_object)) my huge-ass object's size: 5.32 TiB `- Parameters:
desc (str) – string to print along
obj (object) – thing to get the size of
- Return type:
str
- fxutil.get_git_repo_path()¶
Returns the path to the root of the inner most git repository that the working directory resides in, if any. Raises if not contained in any repository.
- Returns:
repository_path
- Return type:
Path
- fxutil.round_by_method(x, ndigits, round_method='round')¶
- Parameters:
x
ndigits
round_method (
str) – One of ‘round’, ‘floor’, ‘ceil’
- fxutil.scinum(a, force_pref=False, round_method='round', ndigits=2, no_trailing_zeros=True, force_mode=None, suffix='\\\\,', thousands_sep='\\\\,')¶
Return LaTeX-formatted string representation of number in scientific notation.
- Parameters:
a – number to format
force_pref (
bool) – force prepending sign prefixround_method (
str) – One of ‘round’, ‘floor’, ‘ceil’ndigits (
int) – Number of decimal placesforce_mode (
Optional[str]) – ‘e’, ‘f’suffix – suffix to append to the number
- Return type:
str
- fxutil.nixt(thing)¶
Get the first element of an iterable.
- Parameters:
thing (
Iterable)- Return type:
First element of the iterable.
- fxutil.thing(which)¶
Return a thing.
(Example data)
- Parameters:
which (
Optional[str])
- fxutil.get_unique_with_bang(iterable)¶
- fxutil.bunny(iterable)¶
- fxutil.parse_combi_args(func=None, exceptions=None)¶
Decorator to parse Combi arguments of a function.
Usage example:
@parse_combi_args def my_function(param: Combi[int] | None): ...
This will ensure that
paramis always treated as an iterable of integers (or None) whenmy_functionis called, even if a single integer is passed.- Parameters:
func (
Optional[Callable]) – The function to decorateexceptions (
list) – Values excluded from modification, e.g., a special string value.
- Return type:
Callable