alphapepttools.pl.create_figure#
- alphapepttools.pl.create_figure(nrows=1, ncols=1, figsize=None, height_ratios=None, width_ratios=None, subplots_kwargs=None, gridspec_kwargs=None)#
Create a figure with a specified number of rows and columns. Returns an AxisManager object to manage axes objects.
This is especially useful for creating subplots with consistent styling. Importantly, it should completely sync the plot a user sees in a jupyter notebook with the exported (e.g. .png) figure file. The aim of this is to entirely eliminate time consuming iterations of checking the exported plot and going back to adjust sizes/padding in the code.
Example:
# This works: fig, axm = create_figure(nrows=2, ncols=2, figsize = (4, 4)) x = np.linspace(0, 10, 100) functions = [lambda x: np.sin(x + 1), lambda x: np.sin(x) * 2, lambda x: np.sin(x) + 2, lambda x: np.sin(x) - 2] for i, func in enumerate(functions):
ax = axm[i] ax.scatter(x, func(x))
# Just the same as this: fig, axm = create_figure(nrows=1, ncols=4, figsize = (8, 2)) x = np.linspace(0, 10, 100) functions = [lambda x: np.sin(x + 1), lambda x: np.sin(x) * 2, lambda x: np.sin(x) + 2, lambda x: np.sin(x) - 2] for i, func in enumerate(functions):
ax = axm[i] ax.scatter(x, func(x))
- Parameters:
nrows (int, optional) – The number of rows in the figure, by default 1
ncols (int, optional) – The number of columns in the figure, by default 1
figsize (tuple[float, float] | tuple[str, str], optional) – The size of the figure in inches. If a tuple of strings is provided, the strings must be valid keys in the config file, by default None
height_ratios (list[float], optional) – The height ratios of the rows in the figure, by default None
width_ratios (list[float], optional) – The width ratios of the columns in the figure, by default None
- Return type:
- Returns:
- -fig (
Figure) The figure object
- axmAxisManager object
An iterable and indexable object to manage matplotlib.axes objects
- -fig (