-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlotter.py
More file actions
63 lines (51 loc) · 1.91 KB
/
Copy pathPlotter.py
File metadata and controls
63 lines (51 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Backward-compatible ``Plotter`` facade.
FLAF imports this module as ``FLAF.PlotKit.Plotter`` and uses exactly this class, so keeping
its signature identical to the legacy ROOT implementation makes the new (matplotlib/mplhep)
renderer a transparent drop-in -- no change is required in the analysis configs or in the
FLAF plotting task beyond the submodule swap.
Legacy usage (unchanged)::
import FLAF.PlotKit.Plotter as Plotter
plotter = Plotter.Plotter(page_cfg, page_cfg_custom, hist_cfg=hist_cfg_dict)
plotter.plot(hist_name, {proc: (TH1, name, color, group)}, out_pdf,
want_data=..., custom=..., scale=...)
"""
from __future__ import annotations
from typing import Optional
from .config import PlotConfig
from .plotters.stacked import StackedPlotter
class Plotter:
def __init__(
self,
page_cfg,
page_cfg_custom=None,
hist_cfg=None,
inputs_cfg=None, # accepted for legacy signature compatibility; unused
backend=None,
):
self.config = PlotConfig(page_cfg, page_cfg_custom, hist_cfg)
self._plotter = StackedPlotter(self.config, _as_backend(backend))
def plot(
self,
hist_name: str,
histograms: dict,
output_file: str,
want_data: bool = True,
custom: Optional[dict] = None,
scale=None,
) -> None:
"""``scale`` is a fixed factor (number, or per-signal dict), or the string ``"bkg"``
to normalise each signal's integral to the summed background (for shape comparison).
"""
self._plotter.plot(
hist_name,
histograms,
output_file,
want_data=want_data,
custom=custom,
scale=scale,
)
def _as_backend(backend):
if backend is None or hasattr(backend, "render_stacked"):
return backend
from .backends import get_backend
return get_backend(backend)