diff --git a/Application/test/default.mplstyle b/Application/test/default.mplstyle index 498b744..59759f6 100644 --- a/Application/test/default.mplstyle +++ b/Application/test/default.mplstyle @@ -4,3 +4,5 @@ xtick.labelsize : 14 ytick.labelsize : 14 figure.autolayout : True figure.figsize : 10, 5 +legend.frameon : True +font.size : 18 diff --git a/Application/test/plotTest.py b/Application/test/plotTest.py index 8c29879..075fb6b 100644 --- a/Application/test/plotTest.py +++ b/Application/test/plotTest.py @@ -1,4 +1,4 @@ -import os +import os, sys from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter from collections import OrderedDict import numpy as np @@ -7,6 +7,14 @@ import matplotlib as mpl mpl.use('Agg') import matplotlib.pyplot as plt + +# mplhep for cms style +sys.path.append(os.getcwd()+'/.local/lib/python2.7/site-packages/') +import mplhep as hep +# avoid incompatibilities +for x in list(hep.cms.style.ROOT.keys()): + if x not in plt.rcParams.keys(): del hep.cms.style.ROOT[x] +plt.style.use(hep.cms.style.ROOT) plt.style.use('default.mplstyle') # check arguments @@ -133,14 +141,28 @@ def make_ratio(numer,denom,rframes,zframes): ratio_title = "ratio" # plotting helper functions +def prop_repr(prop, val): + prop_names = { + "bfield": "Field", + "energy": "Energy", + "mult": "N", + "particle": "Particle" + } + prop_vals = { + "bfield": "{:.1f} T", + "energy": "{:d} GeV", + } + line = (prop_names[prop] if prop in prop_names else prop)+": "+(prop_vals[prop].format(val) if prop in prop_vals else str(val)) + return line def make_plot(): fig, (ax, lax) = plt.subplots(ncols=2, gridspec_kw={"width_ratios":[2.5,1]}) ax.set_prop_cycle(cycler('color',['k','b','m','r','c'])) + ax = hep.cms.cmslabel(ax, data=False, paper=False, rlabel="") return fig, ax, lax def make_legend(ax, lax, frame, ignore_list): # add params to legend handles, labels = ax.get_legend_handles_labels() - patches = [mpl.patches.Patch(color='w', label=p+": "+str(frame["parameters"][p][0])) for p in frame["parameters"] if p not in ignore_list] + patches = [mpl.patches.Patch(color='w', label=prop_repr(p,frame["parameters"][p][0])) for p in frame["parameters"] if p not in ignore_list] handles.extend(patches) labels.extend([patch.get_label() for patch in patches]) legend = lax.legend(handles=handles, labels=labels, borderaxespad=0, loc='upper right') diff --git a/setup.sh b/setup.sh index fd777c5..001b62e 100644 --- a/setup.sh +++ b/setup.sh @@ -21,6 +21,15 @@ if [[ "$UNAME" == *el7* ]]; then OS=slc7 fi +install_mplhep() { + cd $1 + mkdir -p .local/lib/python2.7/site-packages + pip install --prefix `pwd`/.local mplhep + # fix missing import + cp -r /cvmfs/cms.cern.ch/$SCRAM_ARCH/external/py2-matplotlib/1.5.2-gnimlf2/lib/python2.7/site-packages/mpl_toolkits/ .local/lib/python2.7/site-packages/ + touch .local/lib/python2.7/site-packages/mpl_toolkits/__init__.py +} + for SIM in ${SIMS[@]}; do if [ "$SIM" = GV ]; then cd $BASEDIR @@ -45,6 +54,8 @@ for SIM in ${SIMS[@]}; do scram b -j 8 # link to G4 ln -s ${G4DIR}/${TESTDIR} ${GVDIR}/${TESTDIR}/G4 + # for plotting + install_mplhep ${GVDIR}/${TESTDIR} elif [ "$SIM" = G4 ]; then cd $BASEDIR mkdir -p $G4DIR @@ -74,6 +85,8 @@ EOF_SPARSE scram b -j 8 # link to GV ln -s ${GVDIR}/${TESTDIR} ${G4DIR}/${TESTDIR}/GV + # for plotting + install_mplhep ${G4DIR}/${TESTDIR} else echo "Unknown sim value: $SIM" fi