Wrappers#
- @spylt.spylling(as_dir: bool = True, zipped: bool = False, excluded_args: Iterable | None = None, excluded_types: Iterable | None = None, save_env: bool = False, verbose: bool = False)[source]#
Decorator to wrap functions generating a figure to turn it into a SpyllingFigure.
The
spylt.SpyllingFigureinstantiated within the decorated function will be passed the function as plot_fun, and its arguments and keyword arguments as data.- Parameters:
- as_dir
Whether to save the backup in a child directory, named after the figure file’s name.
- zipped
Whether to save the backup in a zipped directory, named after the figure file’s name. If as_dir is True too, only a zip will be saved.
- excluded_args
Iterable of argument names not to save even if they are present in data.
- excluded_types
Iterable of argument types not to save even if they are present in data.
- save_env
Whether to save a file listing the packages installed in the virtual environment (requirements.txt for pip, environment.yml for conda).
- verbose
Whether to print for every file saved to disk.
Examples
A function plotting figures can be directly decorated to always be spylling:
>>> @spylling(verbose=True) ... def plot(dataset, scatter_size=6, cmap='plasma'): ... # Function that creates your figure ... return ax >>> ax = plot(dataset, scatter_size=10) >>> ax.get_figure().savefig('fig.pdf') Saved figure: fig Saving backup data to ./fig Saved plot.py Saved matplotlibrc Saved dataset.pickle Saved scatter_size.pickle Saved cmap.pickle
or you can generate a new decorated function when calling it:
>>> def plot(dataset, scatter_size=6, cmap='plasma'): ... # Function that creates your figure ... return ax >>> ax = spylling(plot)(dataset, scatter_size=10) >>> ax.get_figure().savefig('fig.pdf') Saved figure: fig Saving backup data to ./fig Saved plot.py Saved matplotlibrc Saved dataset.pickle Saved scatter_size.pickle Saved cmap.pickle
- spylt.SpyllingContext(plot_fun: function | module | None = None, data: dict[str, Any] | None = None, as_dir: bool = True, zipped: bool = False, excluded_args: Iterable | None = None, excluded_types: Iterable | None = None, save_env: bool = False, verbose: bool = False)[source]#
Context within which generated figures are turned it into a SpyllingFigure.
- Parameters:
- plot_fun
Function or method used to generate the figure.
- data
Dictionary containing all the data objects necessary to reproduce the figure with plot_fun.
- as_dir
Whether to save the backup in a child directory, named after the figure file’s name.
- zipped
Whether to save the backup in a zipped directory, named after the figure file’s name. If as_dir is True too, only a zip will be saved.
- excluded_args
Iterable of argument names not to save even if they are present in data.
- excluded_types
Iterable of argument types not to save even if they are present in data.
- save_env
Whether to save a file listing the packages installed in the virtual environment (requirements.txt for pip, environment.yml for conda).
- verbose
Whether to print for every file saved to disk.
Examples
>>> with SpyllingContext(verbose=True): ... # Code that creates your figure.