Commit 08765297 authored by thomas.forbriger's avatar thomas.forbriger
Browse files

croposp [FEATURE]: support selection of curves

parent 95f52841
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
# 14/02/2019 V1.1 first version providing reasonable functionality # 14/02/2019 V1.1 first version providing reasonable functionality
# #
# ============================================================================ # ============================================================================
__version__ = "croposplot 2019-02-14 V1.1" __version__ = "croposplot 2019-02-15 V1.2"
__author__ = "Thomas Forbriger" __author__ = "Thomas Forbriger"
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
# backend # backend
...@@ -63,7 +63,7 @@ def usage(): ...@@ -63,7 +63,7 @@ def usage():
print(' [--legfontsize s] [--legpos p] [--title t]') print(' [--legfontsize s] [--legpos p] [--title t]')
print(' [--xlabel l] [--ylabel l] [--titfontsize t]') print(' [--xlabel l] [--ylabel l] [--titfontsize t]')
print(' [--xlim l] [--ylim l]') print(' [--xlim l] [--ylim l]')
print(' [--usemarkers]') print(' [--usemarkers] [--match re]')
print(' file [file [file ...]]') print(' file [file [file ...]]')
print(' or: '+sys.argv[0]+' --help|-h') print(' or: '+sys.argv[0]+' --help|-h')
...@@ -95,6 +95,8 @@ def help(): ...@@ -95,6 +95,8 @@ def help():
--titfontsize s set font size for legend --titfontsize s set font size for legend
--xlim min:max set x-axis limits --xlim min:max set x-axis limits
--ylim min:max set y-axis limits --ylim min:max set y-axis limits
--match re only display curve for which the label matches the regular
expression "re"
""") """)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
...@@ -120,7 +122,7 @@ def main(argv=None): ...@@ -120,7 +122,7 @@ def main(argv=None):
opts, args=getopt.getopt(sys.argv[1:], 'hvo:g', ['help', 'nologlog', opts, args=getopt.getopt(sys.argv[1:], 'hvo:g', ['help', 'nologlog',
'nologx', 'nology', 'grid', 'xlabel=', 'legfontsize=', 'title=', 'nologx', 'nology', 'grid', 'xlabel=', 'legfontsize=', 'title=',
'legpos=', 'titfontsize=', 'ylabel=', 'xlim=', 'ylim=', 'legpos=', 'titfontsize=', 'ylabel=', 'xlim=', 'ylim=',
'usemarkers']) 'usemarkers', 'match='])
except getopt.GetoptError as err: except getopt.GetoptError as err:
print(err.msg) print(err.msg)
exit(0) exit(0)
...@@ -142,6 +144,7 @@ def main(argv=None): ...@@ -142,6 +144,7 @@ def main(argv=None):
opt_xlim = None opt_xlim = None
opt_ylim = None opt_ylim = None
opt_usemarkers = False opt_usemarkers = False
opt_match = None
for (opt, arg) in opts: for (opt, arg) in opts:
if opt == '-v': if opt == '-v':
...@@ -164,6 +167,8 @@ def main(argv=None): ...@@ -164,6 +167,8 @@ def main(argv=None):
raise raise
except: except:
raise Error("Invalid 'ylim' argument.") raise Error("Invalid 'ylim' argument.")
elif opt in ('--match'):
opt_match=arg
elif opt in ('--xlabel'): elif opt in ('--xlabel'):
xlabel=arg xlabel=arg
elif opt in ('--ylabel'): elif opt in ('--ylabel'):
...@@ -235,7 +240,7 @@ def main(argv=None): ...@@ -235,7 +240,7 @@ def main(argv=None):
if opt_ylim is not None: if opt_ylim is not None:
plt.ylim(opt_ylim[0], opt_ylim[1]) plt.ylim(opt_ylim[0], opt_ylim[1])
mymarkers=['o','*','p','v','<','>','P','X','d','D','.'] mymarkers=['o','*','p','v','<','>','d','D','.']
icurve=0 icurve=0
for specfile in args: for specfile in args:
...@@ -248,14 +253,18 @@ def main(argv=None): ...@@ -248,14 +253,18 @@ def main(argv=None):
data=np.loadtxt(specfile, unpack=False) data=np.loadtxt(specfile, unpack=False)
for i in range(1,len(data[0,:])): for i in range(1,len(data[0,:])):
label=re.sub('^# #\d+: ', '', labellines[i-1].strip()) label=re.sub('^# #\d+: ', '', labellines[i-1].strip())
if verbose: match=True
print('plot curve %d: %s' % (i, label)) if opt_match is not None:
themarker=None match=(re.search(opt_match, label) is not None)
if opt_usemarkers: if match:
themarker=mymarkers[icurve % len(mymarkers)] if verbose:
plt.plot(data[:,0], data[:,i], label=label, marker=themarker) print('plot curve %d: %s' % (i, label))
plt.legend(fontsize=opt_legendfontsize, loc=opt_legposition) themarker=None
icurve=1+icurve if opt_usemarkers:
themarker=mymarkers[icurve % len(mymarkers)]
plt.plot(data[:,0], data[:,i], label=label, marker=themarker)
plt.legend(fontsize=opt_legendfontsize, loc=opt_legposition)
icurve=1+icurve
if opt_title is not None: if opt_title is not None:
plt.title(re.sub('\\\\n','\n',opt_title), fontsize=opt_titlefontsize) plt.title(re.sub('\\\\n','\n',opt_title), fontsize=opt_titlefontsize)
......
...@@ -248,7 +248,8 @@ psd%foutra.xxx: psd%.001.asc ...@@ -248,7 +248,8 @@ psd%foutra.xxx: psd%.001.asc
CROPOSPLOT=../croposplot.py CROPOSPLOT=../croposplot.py
# common options # common options
CROPOSPLOT_OPT=--usemarkers CROPOSPLOT_MATCH=.
CROPOSPLOT_OPT=--usemarkers --match='$(CROPOSPLOT_MATCH)'
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
# reference plots # reference plots
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment