Select Git revision
Renderer.meta
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