CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes
python.rootplot.utilities.HistStack Class Reference
Inheritance diagram for python.rootplot.utilities.HistStack:
python.rootplot.root2matplotlib.HistStack

Public Member Functions

def __getitem__ (self, index)
 
def __init__ (self, hists=None, title=None, xlabel=None, ylabel=None)
 
def __iter__ (self)
 
def __len__ (self)
 
def __setitem__ (self, index, value)
 
def add (self, hist, kwargs)
 
def max (self)
 
def min (self, threshold=None)
 
def scale (self, factor)
 
def stackmax (self)
 

Public Attributes

 hists
 
 kwargs
 
 title
 
 xlabel
 
 ylabel
 

Detailed Description

A container to hold Hist objects for plotting together.

When plotting, the title and the x and y labels of the last Hist added
will be used unless specified otherwise in the constructor.

Definition at line 310 of file utilities.py.

Constructor & Destructor Documentation

def python.rootplot.utilities.HistStack.__init__ (   self,
  hists = None,
  title = None,
  xlabel = None,
  ylabel = None 
)

Definition at line 317 of file utilities.py.

317  def __init__(self, hists=None, title=None, xlabel=None, ylabel=None):
318  self.hists = []
319  self.kwargs = []
320  self.title = title
321  self.xlabel = xlabel
322  self.ylabel = ylabel
323  if hists:
324  for hist in hists:
325  self.add(hist)
def __init__(self, hists=None, title=None, xlabel=None, ylabel=None)
Definition: utilities.py:317
def add(self, hist, kwargs)
Definition: utilities.py:365

Member Function Documentation

def python.rootplot.utilities.HistStack.__getitem__ (   self,
  index 
)
Return indexth hist: x.__getitem__(y) <==> x[y]

Definition at line 326 of file utilities.py.

References histograms.Histograms.hists, and python.rootplot.utilities.HistStack.hists.

326  def __getitem__(self, index):
327  """Return indexth hist: x.__getitem__(y) <==> x[y]"""
328  return self.hists[index]
def python.rootplot.utilities.HistStack.__iter__ (   self)
Iterate through hists in the stack: x.__iter__() <==> iter(x)

Definition at line 335 of file utilities.py.

References histograms.Histograms.hists, and python.rootplot.utilities.HistStack.hists.

335  def __iter__(self):
336  """Iterate through hists in the stack: x.__iter__() <==> iter(x)"""
337  return iter(self.hists)
def python.rootplot.utilities.HistStack.__len__ (   self)
Return the number of hists in the stack: x.__len__() <==> len(x)

Definition at line 332 of file utilities.py.

References histograms.Histograms.hists, and python.rootplot.utilities.HistStack.hists.

332  def __len__(self):
333  """Return the number of hists in the stack: x.__len__() <==> len(x)"""
334  return len(self.hists)
def python.rootplot.utilities.HistStack.__setitem__ (   self,
  index,
  value 
)
Replace indexth hist with value: x.__setitem__(i, y) <==> x[i]=y

Definition at line 329 of file utilities.py.

References histograms.Histograms.hists, and python.rootplot.utilities.HistStack.hists.

329  def __setitem__(self, index, value):
330  """Replace indexth hist with value: x.__setitem__(i, y) <==> x[i]=y"""
331  self.hists[index] = value
def __setitem__(self, index, value)
Definition: utilities.py:329
def python.rootplot.utilities.HistStack.add (   self,
  hist,
  kwargs 
)
Add a Hist object to this stack.

Any additional keyword arguments will be added to just this Hist
when the stack is plotted.

Definition at line 365 of file utilities.py.

References histograms.Histograms.hists, and python.rootplot.utilities.HistStack.hists.

Referenced by counter.Counter.register().

365  def add(self, hist, **kwargs):
366  """
367  Add a Hist object to this stack.
368 
369  Any additional keyword arguments will be added to just this Hist
370  when the stack is plotted.
371  """
372  if "label" in kwargs:
373  hist.label = kwargs['label']
374  del kwargs['label']
375  if len(self) > 0:
376  if hist.xedges != self.hists[0].xedges:
377  raise ValueError("Cannot add %s to stack; all Hists must "
378  "have the same binning." % hist.name)
379  self.hists.append(hist)
380  self.kwargs.append(kwargs)
381 
382 
def add(self, hist, kwargs)
Definition: utilities.py:365
def python.rootplot.utilities.HistStack.max (   self)
Return the value of the highest bin of all hists in the stack.

Definition at line 338 of file utilities.py.

References histograms.Histograms.hists, and python.rootplot.utilities.HistStack.hists.

Referenced by python.rootplot.utilities.HistStack.stackmax().

338  def max(self):
339  """Return the value of the highest bin of all hists in the stack."""
340  maxes = [max(x) for x in self.hists]
341  try:
342  return max(maxes)
343  except ValueError:
344  return 0
def python.rootplot.utilities.HistStack.min (   self,
  threshold = None 
)
Return the value of the lowest bin of all hists in the stack.

If threshold is specified, only values above the threshold will be
considered.

Definition at line 356 of file utilities.py.

References histograms.Histograms.hists, and python.rootplot.utilities.HistStack.hists.

356  def min(self, threshold=None):
357  """
358  Return the value of the lowest bin of all hists in the stack.
359 
360  If threshold is specified, only values above the threshold will be
361  considered.
362  """
363  mins = [x.min(threshold) for x in self.hists]
364  return min(mins)
def min(self, threshold=None)
Definition: utilities.py:356
def python.rootplot.utilities.HistStack.scale (   self,
  factor 
)
Scale all Hists by factor.

Definition at line 352 of file utilities.py.

References histograms.Histograms.hists, and python.rootplot.utilities.HistStack.hists.

352  def scale(self, factor):
353  """Scale all Hists by factor."""
354  for hist in self.hists:
355  hist.scale(factor)
def python.rootplot.utilities.HistStack.stackmax (   self)
Return the value of the highest bin in the addition of all hists.

Definition at line 345 of file utilities.py.

References histograms.Histograms.hists, python.rootplot.utilities.HistStack.hists, python.rootplot.utilities.HistStack.max(), and edm.print().

345  def stackmax(self):
346  """Return the value of the highest bin in the addition of all hists."""
347  try:
348  return max([sum([h[i] for h in self.hists])
349  for i in range(self.hists[0].nbins)])
350  except:
351  print([h.nbins for h in self.hists])
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66

Member Data Documentation

python.rootplot.utilities.HistStack.hists
python.rootplot.utilities.HistStack.kwargs
python.rootplot.utilities.HistStack.title
python.rootplot.utilities.HistStack.xlabel
python.rootplot.utilities.HistStack.ylabel