Skip to content

Commit

Permalink
added plotting.GenericResult
Browse files Browse the repository at this point in the history
  • Loading branch information
ibressler committed Jun 8, 2021
1 parent a50f78e commit 96cf6c8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import matplotlib
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager

# increase the limit for the warning to pop up
matplotlib.rcParams['figure.max_open_warning'] = 50
Expand Down Expand Up @@ -36,3 +37,29 @@ def plotColor(idx):

def lineWidth():
return plt.rcParams["lines.linewidth"]

class GenericResult:
color = None

@staticmethod
def getBarWidth(xvec):
return np.concatenate((np.diff(xvec)[:1], np.diff(xvec)))

@classmethod
def plotPeakRange(cls, ax, peakRange, peakDistrib, fullDistrib, moments, distrPar):
x, y, u = peakDistrib
xvec, yvec, uvec = fullDistrib
mom, momLo, momHi = moments
dp, dpLo, dpHi = distrPar
#ax.plot(x, y, 'o', color=cls.color)
lbl, fmt = [], "{: <7s} {: 9.2g} ±{: 9.2g}"
for k in "area", "median", "var", "skew", "kurt":
if k == "median":
lbl.append(fmt.format("median:", dp[-1], max(abs(dp[-1]-dpLo[-1]), abs(dpHi[-1]-dp[-1]))))
else:
lbl.append(fmt.format(k+':', mom[k], max(abs(mom[k]-momLo[k]), abs(momHi[k]-mom[k]))))
ax.bar(x, y, width=cls.getBarWidth(x), color=cls.color, alpha=0.5, label="\n".join(lbl))
ax.fill_between(x, np.maximum(0, y-u), y+u,
color='red', lw=0, alpha=0.1,
label=f"uncertainties (lvl: {1/np.median(y/u):.3g})")
ax.legend(prop=font_manager.FontProperties(family='monospace')); ax.grid(True);

0 comments on commit 96cf6c8

Please sign in to comment.