SubSpectral and Lightning 0.9 Update
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
try:
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
||||
except ImportError: # pragma: no-cover
|
||||
raise ImportError('You want to use `matplotlib` plugins which are not installed yet,' # pragma: no-cover
|
||||
' install it with `pip install matplotlib`.')
|
||||
@ -8,30 +8,23 @@ from pathlib import Path
|
||||
|
||||
|
||||
class Plotter(object):
|
||||
|
||||
def __init__(self, root_path=''):
|
||||
if not root_path:
|
||||
self.root_path = Path(root_path)
|
||||
|
||||
def save_current_figure(self, filename: str, extention='.png', naked=False):
|
||||
fig, _ = plt.gcf(), plt.gca()
|
||||
def save_figure(self, figure, title, extention='.png', naked=False):
|
||||
canvas = FigureCanvas(figure)
|
||||
# Prepare save location and check img file extention
|
||||
path = self.root_path / Path(filename if filename.endswith(extention) else f'{filename}{extention}')
|
||||
path = self.root_path / f'{title}{extention}'
|
||||
path.parent.mkdir(exist_ok=True, parents=True)
|
||||
if naked:
|
||||
plt.axis('off')
|
||||
fig.savefig(path, bbox_inches='tight', transparent=True, pad_inches=0)
|
||||
fig.clf()
|
||||
figure.axis('off)')
|
||||
figure.savefig(path, bbox_inches='tight', transparent=True, pad_inches=0)
|
||||
canvas.print_figure(path)
|
||||
else:
|
||||
fig.savefig(path)
|
||||
fig.clf()
|
||||
|
||||
def show_current_figure(self):
|
||||
fig, _ = plt.gcf(), plt.gca()
|
||||
fig.show()
|
||||
fig.clf()
|
||||
canvas.print_figure(path)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
output_root = Path('..') / 'output'
|
||||
p = Plotter(output_root)
|
||||
p.save_current_figure('test.png')
|
||||
raise PermissionError('Get out of here.')
|
||||
|
Reference in New Issue
Block a user