-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathplot_counts.py
54 lines (41 loc) · 1.52 KB
/
plot_counts.py
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
"""Compute and plot counts spectrum (Fig 1 in the paper)."""
import logging
import matplotlib.pyplot as plt
from .conf import config
log = logging.getLogger(__name__)
def main():
fig, ax = plt.subplots()
for name in config.all_datasets:
dataset = config.datasets[name]
obs = dataset.get_SpectrumObservationList().stack()
ex_obs = obs.excess_vector
energy = ex_obs.energy.nodes.to("TeV")
mask = dataset.get_energy_mask(energy)
bins = ex_obs.energy.bins.to("TeV")
weights = ex_obs.data.data.value
ax.hist(
energy.value[mask],
bins=bins.value,
weights=weights[mask],
histtype="step",
ls="-",
lw=2.2,
color=dataset.color,
label=dataset.label,
)
ax.legend(fontsize=config.plot.fontsize)
ax.set_xscale("log")
ax.set_ylabel("Excess counts", size=config.plot.fontsize)
ax.set_xlabel(r"$E'\,/\,\mathrm{TeV}$", size=config.plot.fontsize)
for axis in ["top", "bottom", "left", "right"]:
ax.spines[axis].set_linewidth(1.6)
opts = dict(axis="both", width=1.6, labelsize=config.plot.fontsize)
ax.tick_params(which="major", length=7, **opts)
ax.tick_params(which="minor", length=4, **opts)
plt.tight_layout()
filename = "results/figures/counts_spectra.png"
log.info(f"Writing {filename}")
fig.savefig(filename)
filename = "results/figures/counts_spectra.pdf"
log.info(f"Writing {filename}")
fig.savefig(filename)