Skip to content

Commit d387915

Browse files
authored
Merge pull request #15 from LPC-HH/dev-plotting-update
Dev plotting update
2 parents 1ed186f + 18271db commit d387915

File tree

1 file changed

+112
-9
lines changed

1 file changed

+112
-9
lines changed

src/boostedhh/plotting.py

Lines changed: 112 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,16 +845,30 @@ def multiROCCurveGreyOld(
845845
plt.close()
846846

847847

848+
# th_colours = [
849+
# "#36213E",
850+
# "#9381FF",
851+
# "#1f78b4",
852+
# "#a6cee3",
853+
# "#32965D",
854+
# "#7CB518",
855+
# "#EDB458",
856+
# "#ff7f00",
857+
# "#a70000",
858+
# ]
859+
860+
# Updated with CMS color palette
848861
th_colours = [
849-
"#36213E",
850-
# "#9381FF",
851-
"#1f78b4",
852-
"#a6cee3",
853-
# "#32965D",
854-
"#7CB518",
855-
"#EDB458",
856-
"#ff7f00",
857-
"#a70000",
862+
"#3f90da",
863+
"#ffa90e",
864+
"#bd1f01",
865+
"#94a4a2",
866+
"#832db6",
867+
"#a96b59",
868+
"#e76300",
869+
"#b9ac70",
870+
"#717581",
871+
"#92dadd",
858872
]
859873

860874

@@ -1124,6 +1138,15 @@ def multiROCCurve(
11241138
# fontproperties="Tex Gyre Heros:bold",
11251139
)
11261140

1141+
# if 'auc' in roc:
1142+
# ax.text(
1143+
# 0.02,
1144+
# 0.83,
1145+
# f"AUC: {roc['auc']:.2f}",
1146+
# transform=ax.transAxes,
1147+
# fontsize=20,
1148+
# )
1149+
11271150
if kin_label:
11281151
ax.text(
11291152
0.05,
@@ -1329,3 +1352,83 @@ def cutsLinePlot(
13291352
plt.show()
13301353
else:
13311354
plt.close()
1355+
1356+
1357+
def plot_hist(
1358+
data,
1359+
sample_names,
1360+
plot_dir="",
1361+
name="",
1362+
nbins=100,
1363+
weights=None,
1364+
xlabel=None,
1365+
text=None,
1366+
xlim=None,
1367+
log=False,
1368+
density=False,
1369+
int_xticks=False,
1370+
lumi=None,
1371+
year=None,
1372+
com=13.6,
1373+
):
1374+
"""Lightweight plotter for histograms.
1375+
Args:
1376+
data (list): List of data arrays to plot.
1377+
sample_names (list): List of sample_names for each data array.
1378+
nbins (int): Number of bins for the histogram.
1379+
weights (list): List of weights for each data array.
1380+
"""
1381+
1382+
hep.style.use("CMS")
1383+
colors = plt.cm.tab10.colors
1384+
fig, ax = plt.subplots(figsize=(12, 9))
1385+
hep.cms.label("Preliminary", data=True, lumi=lumi, year=year, com=com)
1386+
if weights is not None:
1387+
for d, w, sample_name, c in zip(data, weights, sample_names, colors[: len(data)]):
1388+
ax.hist(
1389+
d,
1390+
bins=nbins,
1391+
weights=w,
1392+
range=xlim,
1393+
label=sample_name,
1394+
color=c,
1395+
density=density,
1396+
log=log,
1397+
histtype="step",
1398+
linewidth=2,
1399+
)
1400+
else:
1401+
for d, sample_name, c in zip(data, sample_names, colors[: len(data)]):
1402+
ax.hist(
1403+
d,
1404+
bins=nbins,
1405+
range=xlim,
1406+
label=sample_name,
1407+
color=c,
1408+
density=density,
1409+
log=log,
1410+
histtype="step",
1411+
linewidth=2,
1412+
)
1413+
if xlabel:
1414+
ax.set_xlabel(xlabel)
1415+
if text is not None:
1416+
ax.text(
1417+
0.02,
1418+
0.6,
1419+
text,
1420+
fontsize=13,
1421+
bbox={"facecolor": "white", "edgecolor": "black"},
1422+
transform=ax.transAxes,
1423+
)
1424+
if int_xticks:
1425+
ax.xaxis.get_major_locator().set_params(integer=True)
1426+
ax.set_ylabel("Normalized frequency")
1427+
ax.set_xlim(xlim)
1428+
ax.legend()
1429+
1430+
if len(name):
1431+
plt.savefig(f"{plot_dir}/{name}.pdf", bbox_inches="tight")
1432+
plt.savefig(f"{plot_dir}/{name}.png", bbox_inches="tight")
1433+
1434+
plt.close()

0 commit comments

Comments
 (0)