Skip to content

Commit

Permalink
Merge pull request #10 from kpedro88/PlotStyle
Browse files Browse the repository at this point in the history
Plot updates
  • Loading branch information
kpedro88 authored Oct 28, 2019
2 parents 4a1b607 + 4d1b0a5 commit e7184b3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Application/test/default.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ xtick.labelsize : 14
ytick.labelsize : 14
figure.autolayout : True
figure.figsize : 10, 5
legend.frameon : True
font.size : 18
26 changes: 24 additions & 2 deletions Application/test/plotTest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import os, sys
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from collections import OrderedDict
import numpy as np
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down
13 changes: 13 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e7184b3

Please sign in to comment.