combine_and_save_figures#

scikitplot.utils.helpers.combine_and_save_figures(figures, save_path='combined_figures.png', figsize=None, dpi=100, to_save=True)#

Combine multiple figures into a single image, save it (if specified), and return the combined figure.

Parameters:
  • figures (tuple of matplotlib.figure.Figure) – Tuple containing the figures to be combined.

  • save_path (str, optional) – Path where the combined figure image will be saved. Default is ‘combined_figure.png’.

  • figsize (tuple of two int or float, optional) – Size of the combined figure (width, height) in inches. If None, defaults to (12, 3.15 * num_figures), where num_figures is the number of figures to combine. Default is None.

  • dpi (int, optional) – Dots per inch (DPI) for the saved figure. Higher DPI results in better resolution. Default is 100.

  • to_save (bool, optional) – Whether to save the combined figure to a file. If False, the figure is not saved. Default is True.

Returns:

combined_fig – The combined figure containing all the individual figures.

Return type:

matplotlib.figure.Figure

Examples

>>> import matplotlib.pyplot as plt
>>> fig1, ax1 = plt.subplots()
>>> ax1.plot([1, 2, 3], [4, 5, 6])
>>> ax1.set_title('Figure 1')
>>> fig2, ax2 = plt.subplots()
>>> ax2.bar(['A', 'B', 'C'], [3, 7, 2])
>>> ax2.set_title('Figure 2')
>>> # Save the combined figure with default figsize
>>> combined_fig = combine_and_save_figures((fig1, fig2), 'output.png', dpi=150, to_save=True)
>>> # Combine figures without saving to a file and with custom figsize
>>> combined_fig = combine_and_save_figures((fig1, fig2), dpi=150, to_save=False, figsize=(14, 7))