Skip to content
Snippets Groups Projects
Commit bed0e7b8 authored by Adrien Crovato's avatar Adrien Crovato
Browse files

Add arguments to tbox plot util

parent fab1af11
No related branches found
No related tags found
1 merge request!6amfe v1.0.5
Pipeline #8615 passed
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2020 University of Liège # Copyright 2020 University of Liège
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -23,7 +23,6 @@ Adrien Crovato ...@@ -23,7 +23,6 @@ Adrien Crovato
def myrange(start, stop, step): def myrange(start, stop, step):
"""Extended range with custom step """Extended range with custom step
Adrien Crovato
""" """
vec = [] vec = []
i = start i = start
...@@ -32,33 +31,34 @@ def myrange(start, stop, step): ...@@ -32,33 +31,34 @@ def myrange(start, stop, step):
i += step i += step
return vec return vec
def plot(x, y, xlbl, ylbl, title, invert=False): def plot(x, y, cfg):
"""Plot using matplotlib """Plot using matplotlib
Adrien Crovato
@todo extend to pass unlimited number of arguments
""" """
from fwk.wutils import parseargs from fwk.wutils import parseargs
args = parseargs() args = parseargs()
if not args.nogui: if not args.nogui:
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
# define font # define font
font = {'family': 'serif', font = {'family': 'serif', 'color': 'darkred', 'weight': 'normal', 'size': 16}
'color': 'darkred',
'weight': 'normal',
'size': 16,}
# plot results # plot results
plt.plot(x, y, 'b-',lw=2) plt.plot(x, y, 'b-', lw=2)
plt.xlabel(xlbl, fontdict=font) if 'xlabel' in cfg:
plt.ylabel(ylbl, fontdict=font) plt.xlabel(cfg['xlabel'], fontdict=font)
plt.title(title, fontdict=font) if 'ylabel' in cfg:
if invert: 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.gca().invert_yaxis()
#plt.grid(True) # display
plt.show() plt.show()
def sort(id, data): def sort(id, data):
"""Sort data array against id (line connectivity list) """Sort data array against id (line connectivity list)
Adrien Crovato
""" """
import numpy as np import numpy as np
# sort id vector # sort id vector
...@@ -76,7 +76,6 @@ def sort(id, data): ...@@ -76,7 +76,6 @@ def sort(id, data):
def read(filename): def read(filename):
"""Read from file and store in data array """Read from file and store in data array
Adrien Croavto
""" """
import io import io
import numpy as np import numpy as np
...@@ -89,7 +88,6 @@ def read(filename): ...@@ -89,7 +88,6 @@ def read(filename):
def write(data, name, frmt, dlm, hdr, cmts): def write(data, name, frmt, dlm, hdr, cmts):
"""Write data array to file """Write data array to file
Adrien Crovato
""" """
import numpy as np import numpy as np
print('writing data file ' + name + '.') print('writing data file ' + name + '.')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment