Exemplo n.º 1
0
def test_plotgrid():
    # histogram creation and manipulation
    from coffea import hist
    # matplotlib
    import matplotlib as mpl
    mpl.use('Agg')
    import matplotlib.pyplot as plt

    lepton_kinematics = fill_lepton_kinematics()

    # Let's stack them, after defining some nice styling
    stack_fill_opts = {'alpha': 0.8, 'edgecolor': (0, 0, 0, .5)}
    stack_error_opts = {
        'label': 'Stat. Unc.',
        'hatch': '///',
        'facecolor': 'none',
        'edgecolor': (0, 0, 0, .5),
        'linewidth': 0
    }
    # maybe we want to compare different eta regions
    # plotgrid accepts row and column axes, and creates a grid of 1d plots as appropriate
    fig, ax = hist.plotgrid(
        lepton_kinematics,
        row="eta",
        overlay="flavor",
        stack=True,
        fill_opts=stack_fill_opts,
        error_opts=stack_error_opts,
    )
Exemplo n.º 2
0
def test_plotgrid():
    # histogram creation and manipulation
    from coffea import hist

    # matplotlib
    import matplotlib.pyplot as plt

    plt.switch_backend("agg")

    lepton_kinematics = fill_lepton_kinematics()

    # Let's stack them, after defining some nice styling
    stack_fill_opts = {"alpha": 0.8, "edgecolor": (0, 0, 0, 0.5)}
    stack_error_opts = {
        "label": "Stat. Unc.",
        "hatch": "///",
        "facecolor": "none",
        "edgecolor": (0, 0, 0, 0.5),
        "linewidth": 0,
    }
    # maybe we want to compare different eta regions
    # plotgrid accepts row and column axes, and creates a grid of 1d plots as appropriate
    axs = hist.plotgrid(
        lepton_kinematics,
        row="eta",
        overlay="flavor",
        stack=True,
        fill_opts=stack_fill_opts,
        error_opts=stack_error_opts,
    )

    return axs.flatten()[0].figure
Exemplo n.º 3
0
}

histo.scale(scales, axis='sample')

#display(histo.identifiers('sample'))
#display(histo.identifiers('x'))

## Write root files
'''
import uproot
import os

if os.path.exists("output.root"):
    os.remove("output.root")
outputfile = uproot.create("output.root")
h = histo.sum('x', 'y')
for sample in h.identifiers('sample'):
	print(sample)
	outputfile[sample.name] = hist.export1d(h.integrate('sample', sample))
outputfile.close()
'''

## Plotting

hnew = (histo.rebin("y",
                    hist.Bin("ynew", "rebinned y value", [0, 3, 5])).rebin(
                        "z", hist.Bin("znew", "rebinned z value", [5, 8, 10])))

hist.plotgrid(hnew, row='ynew', col='znew', overlay='sample')
plt.show()