From 31243bcc6fe41a0dacd8e6f3a94c73b047101d09 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong" Date: Thu, 4 Oct 2018 15:41:15 +0200 Subject: [PATCH] report_quality to init_backend. --- lasp/tools/__init__.py | 5 ++-- lasp/tools/config.py | 60 +++++++++++++++++++++--------------------- lasp/tools/plot.py | 11 +++----- 3 files changed, 36 insertions(+), 40 deletions(-) diff --git a/lasp/tools/__init__.py b/lasp/tools/__init__.py index 3a47535..04da443 100644 --- a/lasp/tools/__init__.py +++ b/lasp/tools/__init__.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from .config import report_quality -from .report_tools import * +from .config import init_backend from lasp.lasp_common import FreqWeighting, TimeWeighting -__all__ = ['report_quality', 'PSPlot', 'LevelBars', 'Levels', 'close', +__all__ = ['init_backend', 'FreqWeighting', 'TimeWeighting'] diff --git a/lasp/tools/config.py b/lasp/tools/config.py index 5210547..66313ea 100644 --- a/lasp/tools/config.py +++ b/lasp/tools/config.py @@ -5,40 +5,40 @@ Author: J.A. de Jong - ASCEE Description: """ -__all__ = ['report_quality', 'getReportQuality'] +__all__ = ['init_backend', 'getReportQuality'] _report_quality = False +_init = False + + +def init_backend(report_quality=False): + global _init + if not _init: + print('Initializing matplotlib...') + _init = True + import matplotlib + matplotlib.use('Qt5Agg') + preamble = [ + r'\usepackage{libertine-type1}' + r'\usepackage[libertine]{newtxmath}' + # r'\usepackage{fontspec}', + # r'\setmainfont{Libertine}', + ] + params = { + 'font.family': 'serif', + 'text.usetex': True, + 'text.latex.unicode': True, + 'pgf.rcfonts': False, + 'pgf.texsystem': 'pdflatex', + 'pgf.preamble': preamble, + } + matplotlib.rcParams.update(params) + global _report_quality + _report_quality = report_quality + import matplotlib.pyplot as plt + plt.ion() def getReportQuality(): global _report_quality return _report_quality - - -def report_quality(): - import matplotlib as mpl - # 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 = [ - r'\usepackage{libertine-type1}' - r'\usepackage[libertine]{newtxmath}' - # r'\usepackage{fontspec}', - # r'\setmainfont{Libertine}', - ] - params = { - 'font.family': 'serif', - 'text.usetex': True, - 'text.latex.unicode': True, - 'pgf.rcfonts': False, - 'pgf.texsystem': 'pdflatex', - 'pgf.preamble': preamble, - } - mpl.rcParams.update(params) - - _report_quality = True diff --git a/lasp/tools/plot.py b/lasp/tools/plot.py index 192d4d7..fe8f11b 100644 --- a/lasp/tools/plot.py +++ b/lasp/tools/plot.py @@ -15,9 +15,6 @@ from lasp.lasp_common import (PLOT_COLORS_LIST, PLOT_NOCOLORS_LIST, DEFAULT_FIGSIZE_H, DEFAULT_FIGSIZE_W) -def close(): - plt.close('all') - class Figure: def __init__(self, **kwargs): @@ -43,7 +40,8 @@ class Figure: linewidths = cycler(linewidth=[1, 2, 1, 2, 2, 3, 2, 1]) - linestyles = cycler(linestyle=['-', '-', '--', ':', '-', '--', ':', '-.', ]) + linestyles = cycler( + linestyle=['-', '-', '--', ':', '-', '--', ':', '-.', ]) self._ax = [] self._legend = {} @@ -75,8 +73,7 @@ class Figure: for ax in self._ax: ax.grid(True, 'both') self._zorder -= 1 - if not getReportQuality(): - self._f.show() + self.fig.show() def vline(self, x): self._ax[0].axvline(x) @@ -121,7 +118,7 @@ class Figure: self._cur_ax.legend(self._legend[self._cur_col][self._cur_col]) def savefig(self, *args, **kwargs): - self._f.savefig(*args, **kwargs) + self.fig.savefig(*args, **kwargs) def xlim(self, *args, **kwargs): all_ax = kwargs.pop('all_ax', False)