diff --git a/tbox/utils.py b/tbox/utils.py index 7d32f8dc690809a80540655a25e8fec2f554b97d..73ec554d506fbd70468392746b5890de2e38da2c 100644 --- a/tbox/utils.py +++ b/tbox/utils.py @@ -2,13 +2,13 @@ # -*- coding: utf-8 -*- # Copyright 2020 University of Liège -# +# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,7 +23,6 @@ Adrien Crovato def myrange(start, stop, step): """Extended range with custom step - Adrien Crovato """ vec = [] i = start @@ -32,33 +31,34 @@ def myrange(start, stop, step): i += step return vec -def plot(x, y, xlbl, ylbl, title, invert=False): +def plot(x, y, cfg): """Plot using matplotlib - Adrien Crovato - @todo extend to pass unlimited number of arguments """ from fwk.wutils import parseargs args = parseargs() if not args.nogui: import matplotlib.pyplot as plt # define font - font = {'family': 'serif', - 'color': 'darkred', - 'weight': 'normal', - 'size': 16,} + font = {'family': 'serif', 'color': 'darkred', 'weight': 'normal', 'size': 16} # plot results - plt.plot(x, y, 'b-',lw=2) - plt.xlabel(xlbl, fontdict=font) - plt.ylabel(ylbl, fontdict=font) - plt.title(title, fontdict=font) - if invert: + plt.plot(x, y, 'b-', lw=2) + if 'xlabel' in cfg: + plt.xlabel(cfg['xlabel'], fontdict=font) + if 'ylabel' in cfg: + plt.ylabel(cfg['ylabel'], fontdict=font) + if 'title' in cfg: + plt.title(cfg['title'], fontdict=font) + if 'xlim' in cfg: + plt.xlim(cfg['xlim']) + if 'ylim' in cfg: + plt.ylim(cfg['ylim']) + if 'invert' in cfg and cfg['invert']: plt.gca().invert_yaxis() - #plt.grid(True) + # display plt.show() def sort(id, data): """Sort data array against id (line connectivity list) - Adrien Crovato """ import numpy as np # sort id vector @@ -76,7 +76,6 @@ def sort(id, data): def read(filename): """Read from file and store in data array - Adrien Croavto """ import io import numpy as np @@ -89,7 +88,6 @@ def read(filename): def write(data, name, frmt, dlm, hdr, cmts): """Write data array to file - Adrien Crovato """ import numpy as np print('writing data file ' + name + '.')