Skip to content
Snippets Groups Projects
Select Git revision
  • develop
  • master default protected
  • feature/build
  • VA_v2022a
  • v2021.a
  • v2020.a
  • v2019.a
  • v2018.b
  • v2017.c
  • v2017.a
  • v2016.a
11 results

Renderer.meta

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