Skip to content
Snippets Groups Projects
Select Git revision
  • 198d707df80662c8a083f2e0333571413a7bbe45
  • main default protected
  • gitkeep
  • dev
  • ipynb
  • 81-add-id-to-figure-file-metadata
  • v0.3.2
  • v0.3.1
  • v0.3.0
  • v0.2.3
  • test_tag
  • v0.2.2
  • v.0.2.1
  • v0.2.1
  • v0.1.2
  • v0.1.1
  • v0.1.0
17 results

save_plot.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    save_plot.py 910 B
    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    """
    Export a plot figure to a picture file.
    
    Functions:
        save_plot(figure, string) -> path-like
    """
    
    import matplotlib
    import matplotlib.pyplot as plt
    
    
    def save_plot(figure, plot_name, extension='png'):
        """
        Export plot.
    
        Parameters
        ----------
        figure : figure object
            Figure that was tagged and now should be saved as picture.
        plot_name: Name of the file where the plot will be saved to.
        extension: string
            File extension for the plot export.
    
        Returns
        -------
        plot_path: Name of the created picture.
    
        """
        match type(figure):
            case matplotlib.figure.Figure:
                plt.figure(figure)
                plot_path = plot_name + '.' + extension
                plt.savefig(plot_path)
            case _:
                raise TypeError('The given figure is not a valid figure object.')
    
        return plot_path