55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
# \file SaveFig.py
|
|
# \brief TODO
|
|
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
|
# \version 0.1
|
|
# \date 09 avril 2018
|
|
#
|
|
# TODO details
|
|
|
|
from ld2dap.core import Output
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
class ShowFig(Output):
|
|
def __init__(self, stack_id=0, symb=False, fname=None, bbox_inches='tight', pad_inches=1, vmax=None):
|
|
super().__init__(self.__class__.__name__)
|
|
self.bbox_inches = bbox_inches
|
|
self.pad_inches = pad_inches
|
|
self.stack_id = stack_id
|
|
self.symb = symb
|
|
self.fname = fname
|
|
self.vmax = vmax
|
|
|
|
def _process(self, data, metadata):
|
|
if self.stack_id == 'all':
|
|
for stack in metadata:
|
|
self._showfig(data, stack)
|
|
else:
|
|
stack = metadata[self.stack_id]
|
|
self._showfig(data, stack)
|
|
|
|
def _showfig(self, data, stack):
|
|
self.logger.info('Display {}'.format(stack))
|
|
fig_count = stack.end - stack.begin
|
|
|
|
im_size = 2
|
|
fig = plt.figure(figsize=(16*im_size,3*im_size*fig_count))
|
|
|
|
for i, di in enumerate(range(stack.begin, stack.end)):
|
|
f1 = fig.add_subplot(fig_count, 1, i + 1)
|
|
img = f1.imshow(data[:,:,di], vmax=self.vmax)
|
|
plt.colorbar(img)
|
|
if self.symb:
|
|
plt.rc('text', usetex=True)
|
|
f1.set_title('${}$'.format(''.join(filter(None, stack.symb[i]))))
|
|
else:
|
|
plt.rc('text', usetex=False)
|
|
f1.set_title(' > '.join(filter(None, stack.desc[i])))
|
|
|
|
if self.fname is not None:
|
|
fig.savefig(self.fname, bbox_inches=self.bbox_inches, pad_inches=self.pad_inches)
|
|
plt.show()
|
|
plt.close(fig)
|