report_quality to init_backend.

This commit is contained in:
Anne de Jong 2018-10-04 15:41:15 +02:00 committed by J.A. de Jong - ASCEE
parent 38d1cfe435
commit 31243bcc6f
3 changed files with 36 additions and 40 deletions

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from .config import report_quality from .config import init_backend
from .report_tools import *
from lasp.lasp_common import FreqWeighting, TimeWeighting from lasp.lasp_common import FreqWeighting, TimeWeighting
__all__ = ['report_quality', 'PSPlot', 'LevelBars', 'Levels', 'close', __all__ = ['init_backend',
'FreqWeighting', 'TimeWeighting'] 'FreqWeighting', 'TimeWeighting']

View File

@ -5,26 +5,19 @@ Author: J.A. de Jong - ASCEE
Description: Description:
""" """
__all__ = ['report_quality', 'getReportQuality'] __all__ = ['init_backend', 'getReportQuality']
_report_quality = False _report_quality = False
_init = False
def getReportQuality(): def init_backend(report_quality=False):
global _report_quality global _init
return _report_quality if not _init:
print('Initializing matplotlib...')
_init = True
def report_quality(): import matplotlib
import matplotlib as mpl matplotlib.use('Qt5Agg')
# mpl.use('Qt5Agg')
global _report_quality
# mpl.use("pgf")
# rc('font',**{'family':'serif','serif':['Libertine']})
# for Palatino and other serif fonts use:
# rc('font',**{'family':'serif','serif':['Palatino']})
# rc('text', usetex=True)
# TeX preamble
preamble = [ preamble = [
r'\usepackage{libertine-type1}' r'\usepackage{libertine-type1}'
r'\usepackage[libertine]{newtxmath}' r'\usepackage[libertine]{newtxmath}'
@ -39,6 +32,13 @@ def report_quality():
'pgf.texsystem': 'pdflatex', 'pgf.texsystem': 'pdflatex',
'pgf.preamble': preamble, 'pgf.preamble': preamble,
} }
mpl.rcParams.update(params) matplotlib.rcParams.update(params)
global _report_quality
_report_quality = report_quality
import matplotlib.pyplot as plt
plt.ion()
_report_quality = True
def getReportQuality():
global _report_quality
return _report_quality

View File

@ -15,9 +15,6 @@ from lasp.lasp_common import (PLOT_COLORS_LIST, PLOT_NOCOLORS_LIST,
DEFAULT_FIGSIZE_H, DEFAULT_FIGSIZE_W) DEFAULT_FIGSIZE_H, DEFAULT_FIGSIZE_W)
def close():
plt.close('all')
class Figure: class Figure:
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -43,7 +40,8 @@ class Figure:
linewidths = cycler(linewidth=[1, 2, 1, 2, 2, 3, 2, 1]) linewidths = cycler(linewidth=[1, 2, 1, 2, 2, 3, 2, 1])
linestyles = cycler(linestyle=['-', '-', '--', ':', '-', '--', ':', '-.', ]) linestyles = cycler(
linestyle=['-', '-', '--', ':', '-', '--', ':', '-.', ])
self._ax = [] self._ax = []
self._legend = {} self._legend = {}
@ -75,8 +73,7 @@ class Figure:
for ax in self._ax: for ax in self._ax:
ax.grid(True, 'both') ax.grid(True, 'both')
self._zorder -= 1 self._zorder -= 1
if not getReportQuality(): self.fig.show()
self._f.show()
def vline(self, x): def vline(self, x):
self._ax[0].axvline(x) self._ax[0].axvline(x)
@ -121,7 +118,7 @@ class Figure:
self._cur_ax.legend(self._legend[self._cur_col][self._cur_col]) self._cur_ax.legend(self._legend[self._cur_col][self._cur_col])
def savefig(self, *args, **kwargs): def savefig(self, *args, **kwargs):
self._f.savefig(*args, **kwargs) self.fig.savefig(*args, **kwargs)
def xlim(self, *args, **kwargs): def xlim(self, *args, **kwargs):
all_ax = kwargs.pop('all_ax', False) all_ax = kwargs.pop('all_ax', False)