Skip to content

Commit c544d90

Browse files
author
Mori Ludovico
committed
small changes in plotting
1 parent d9319b7 commit c544d90

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/boostedhh/plotting.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,15 @@ def multiROCCurve(
11381138
# fontproperties="Tex Gyre Heros:bold",
11391139
)
11401140

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+
11411150
if kin_label:
11421151
ax.text(
11431152
0.05,
@@ -1347,11 +1356,12 @@ def cutsLinePlot(
13471356

13481357
def plot_hist(
13491358
data,
1350-
names,
1359+
sample_names,
1360+
plot_dir="",
1361+
name="",
13511362
nbins=100,
13521363
weights=None,
13531364
xlabel=None,
1354-
saveas=None,
13551365
text=None,
13561366
xlim=None,
13571367
log=False,
@@ -1364,7 +1374,7 @@ def plot_hist(
13641374
"""Lightweight plotter for histograms.
13651375
Args:
13661376
data (list): List of data arrays to plot.
1367-
names (list): List of names for each data array.
1377+
sample_names (list): List of sample_names for each data array.
13681378
nbins (int): Number of bins for the histogram.
13691379
weights (list): List of weights for each data array.
13701380
"""
@@ -1374,26 +1384,26 @@ def plot_hist(
13741384
fig, ax = plt.subplots(figsize=(12, 9))
13751385
hep.cms.label("Preliminary", data=True, lumi=lumi, year=year, com=com)
13761386
if weights is not None:
1377-
for d, w, name, c in zip(data, weights, names, colors[: len(data)]):
1387+
for d, w, sample_name, c in zip(data, weights, sample_names, colors[: len(data)]):
13781388
ax.hist(
13791389
d,
13801390
bins=nbins,
13811391
weights=w,
13821392
range=xlim,
1383-
label=name,
1393+
label=sample_name,
13841394
color=c,
13851395
density=density,
13861396
log=log,
13871397
histtype="step",
13881398
linewidth=2,
13891399
)
13901400
else:
1391-
for d, name, c in zip(data, names, colors[: len(data)]):
1401+
for d, sample_name, c in zip(data, sample_names, colors[: len(data)]):
13921402
ax.hist(
13931403
d,
13941404
bins=nbins,
13951405
range=xlim,
1396-
label=name,
1406+
label=sample_name,
13971407
color=c,
13981408
density=density,
13991409
log=log,
@@ -1416,7 +1426,9 @@ def plot_hist(
14161426
ax.set_ylabel("Normalized frequency")
14171427
ax.set_xlim(xlim)
14181428
ax.legend()
1419-
if saveas:
1420-
plt.savefig(saveas, bbox_inches="tight")
1421-
print(f"saved figure as {saveas}")
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+
14221434
plt.close()

0 commit comments

Comments
 (0)