Skip to content

Commit

Permalink
fix: overflow 2d weird pending
Browse files Browse the repository at this point in the history
- remove overflow ticklabels
- fix broken axis signs with correpsponding pending axis
- fix binnings & pad nan for flow axis
  • Loading branch information
Ming-Yan committed Aug 17, 2023
1 parent fe24f8d commit 711138a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/mplhep/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ def iterable_not_string(arg):
xticks[0] = ""
xticks[1] = f"<{flow_bins[2]}"

ax.set_xticklabels(xticks)
if overflow != 0.0:
if flow == "hint":
ax.plot(
Expand Down Expand Up @@ -676,7 +675,7 @@ def hist2dplot(
*xbins,
]
)
H = np.insert(H, (1), np.nan, axis=-1)
H = np.insert(H, (1), np.full(np.shape(H)[1], np.nan), axis=0)
else:
H = H[1:]
if any(h.values(flow=True)[-1] != 0):
Expand All @@ -687,7 +686,7 @@ def hist2dplot(
xbins[-1] + (xbins[-1] - xbins[0]) * 0.08,
]
)
H = np.insert(H, (-1), np.nan, axis=-1)
H = np.insert(H, (-1), np.full(np.shape(H)[1], np.nan), axis=0)
else:
H = H[:-1]
if any(h.values(flow=True)[:, 0] != 0):
Expand All @@ -698,7 +697,7 @@ def hist2dplot(
*ybins,
]
)
H = np.insert(H, (1), np.full(np.shape(H)[1], np.nan), axis=0)
H = np.insert(H, (1), np.nan, axis=-1)
else:
H = H[:, 1:]
if any(h.values(flow=True)[:, -1] != 0):
Expand All @@ -709,7 +708,7 @@ def hist2dplot(
ybins[-1] + (ybins[-1] - ybins[0]) * 0.08,
]
)
H = np.insert(H, (-1), np.full(np.shape(H)[1], np.nan), axis=0)
H = np.insert(H, (-1), np.nan, axis=-1)
else:
H = H[:, :-1]
elif flow == "sum":
Expand Down Expand Up @@ -809,8 +808,11 @@ def hist2dplot(
**kwargs,
)
if flow == "show":
ax.plot([xbins[1], xbins[2]], [ybins[-1], ybins[-1]], **kwargs)
ax.plot([xbins[1], xbins[2]], [0, 0], transform=trans, **kwargs)
ax.plot([xbins[0], xbins[0]], [ybins[1], ybins[2]], **kwargs)
xtick_labels = ax.get_xticklabels()
xtick_labels[0] = ""
ax.set_xticklabels(xtick_labels)
if any(h.values(flow=True)[:, 0] != 0):
if flow == "hint":
ax.plot(
Expand All @@ -823,8 +825,11 @@ def hist2dplot(
**kwargs,
)
if flow == "show":
ax.plot([xbins[-3], xbins[-2]], [0, 0], transform=trans, **kwargs)
ax.plot([xbins[0], xbins[0]], [ybins[1], ybins[2]], **kwargs)
ax.plot([xbins[-1], xbins[-1]], [ybins[1], ybins[2]], **kwargs)
ytick_labels = ax.get_yticklabels()
ytick_labels[0], ytick_labels[1] = "", ""
ax.set_yticklabels(ytick_labels)
if any(h.values(flow=True)[-1] != 0):
if flow == "hint":
ax.plot(
Expand All @@ -837,8 +842,8 @@ def hist2dplot(
**kwargs,
)
if flow == "show":
ax.plot([xbins[1], xbins[2]], [1, 1], transform=trans, **kwargs)
ax.plot([xbins[0], xbins[0]], [ybins[-3], ybins[-2]], **kwargs)
ax.plot([xbins[-1], xbins[-1]], [ybins[-3], ybins[-2]], **kwargs)

if any(h.values(flow=True)[:, -1] != 0):
if flow == "hint":
Expand All @@ -853,8 +858,10 @@ def hist2dplot(
)
if flow == "show":
ax.plot([xbins[-3], xbins[-2]], [1, 1], transform=trans, **kwargs)
ax.plot([xbins[-1], xbins[-1]], [ybins[-3], ybins[-2]], **kwargs)

ax.plot([xbins[-3], xbins[-2]], [0, 0], transform=trans, **kwargs)
ytick_labels = ax.get_yticklabels()
ytick_labels[-2], ytick_labels[-1] = "", ""
ax.set_yticklabels(ytick_labels)
_labels: np.ndarray | None = None
if isinstance(labels, bool):
_labels = H if labels else None
Expand Down

0 comments on commit 711138a

Please sign in to comment.