Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/mplhep/comparison_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,6 @@ def hists(

ax_comparison.set_xticks(filtered_ticks)
ax_comparison.set_xticklabels(tick_labels)
else:
# For other flow options, control label visibility and regenerate labels
ax_main.tick_params(labelbottom=False)
ax_comparison.tick_params(labelbottom=True)
# Explicitly regenerate tick labels on the comparison axis
# (they may have been set to empty strings during plotting)
tick_positions = ax_comparison.get_xticks()
ax_comparison.set_xticks(tick_positions)
ax_comparison.set_xticklabels([f"{tick:g}" for tick in tick_positions])

return fig, ax_main, ax_comparison


Expand Down Expand Up @@ -859,14 +849,4 @@ def sum_components(x):

ax_comparison.set_xticks(filtered_ticks)
ax_comparison.set_xticklabels(tick_labels)
else:
# For other flow options, control label visibility and regenerate labels
ax_main.tick_params(labelbottom=False)
ax_comparison.tick_params(labelbottom=True)
# Explicitly regenerate tick labels on the comparison axis
# (they may have been set to empty strings during plotting)
tick_positions = ax_comparison.get_xticks()
ax_comparison.set_xticks(tick_positions)
ax_comparison.set_xticklabels([f"{tick:g}" for tick in tick_positions])

return fig, ax_main, ax_comparison
57 changes: 25 additions & 32 deletions src/mplhep/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,43 +718,36 @@ def iterable_not_string(arg):
msg = "No figure found"
raise ValueError(msg)
if flow == "hint":
# Get all shared x-axes to draw markers on all of them
shared_axes = ax.get_shared_x_axes().get_siblings(ax)
shared_axes = [
_ax for _ax in shared_axes if _ax.get_position().x0 == ax.get_position().x0
]

_marker_size = (
30
* ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted()).width
)

# Draw markers on all shared axes
for _ax in shared_axes:
if underflow > 0.0:
_ax.scatter(
final_bins[0],
0,
_marker_size,
marker=align_marker("<", halign="right"),
edgecolor="black",
zorder=5,
clip_on=False,
facecolor="white",
transform=_ax.get_xaxis_transform(),
)
if overflow > 0.0:
_ax.scatter(
final_bins[-1],
0,
_marker_size,
marker=align_marker(">", halign="left"),
edgecolor="black",
zorder=5,
clip_on=False,
facecolor="white",
transform=_ax.get_xaxis_transform(),
)
# Draw markers only on the current axis
if underflow > 0.0:
ax.scatter(
final_bins[0],
0,
_marker_size,
marker=align_marker("<", halign="right"),
edgecolor="black",
zorder=5,
clip_on=False,
facecolor="white",
transform=ax.get_xaxis_transform(),
)
if overflow > 0.0:
ax.scatter(
final_bins[-1],
0,
_marker_size,
marker=align_marker(">", halign="left"),
edgecolor="black",
zorder=5,
clip_on=False,
facecolor="white",
transform=ax.get_xaxis_transform(),
)

elif flow == "show":
lw = ax.spines["bottom"].get_linewidth()
Expand Down
Binary file modified tests/baseline/1d_comparison_asymmetry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/1d_comparison_difference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/1d_comparison_pull.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/1d_comparison_ratio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/1d_comparison_relative_difference.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/1d_comparison_split_ratio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/model_all_comparisons_no_model_unc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/from_issues/baseline/test_issue_594.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions tests/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_simple(mock_matplotlib):
bins = [0, 1, 2, 3]
mh.histplot(h, bins, yerr=True, label="X", ax=ax)

assert len(ax.mock_calls) == 17 # Updated count due to shared axes functionality
assert len(ax.mock_calls) == 13 # Updated count after removing shared axes iteration

ax.stairs.assert_called_once_with(
values=approx([1.0, 3.0, 2.0]),
Expand Down Expand Up @@ -101,15 +101,15 @@ def test_histplot_real(mock_matplotlib):
mh.histplot([a, b, c], bins=bins, ax=ax, yerr=True, label=["MC1", "MC2", "Data"])
ax.legend()
ax.set_title("Raw")
assert len(ax.mock_calls) == 31 # Updated count due to shared axes functionality
assert len(ax.mock_calls) == 27 # Updated count after removing shared axes iteration

ax.reset_mock()

mh.histplot([a, b], bins=bins, ax=ax, stack=True, label=["MC1", "MC2"])
mh.histplot([c], bins=bins, ax=ax, yerr=True, histtype="errorbar", label="Data")
ax.legend()
ax.set_title("Data/MC")
assert len(ax.mock_calls) == 28 # Updated count due to shared axes functionality
assert len(ax.mock_calls) == 20 # Updated count after removing shared axes iteration
ax.reset_mock()

mh.histplot(
Expand All @@ -126,7 +126,7 @@ def test_histplot_real(mock_matplotlib):
)
ax.legend()
ax.set_title("Data/MC binwnorm")
assert len(ax.mock_calls) == 28 # Updated count due to shared axes functionality
assert len(ax.mock_calls) == 20 # Updated count after removing shared axes iteration
ax.reset_mock()

mh.histplot(
Expand All @@ -143,4 +143,4 @@ def test_histplot_real(mock_matplotlib):
)
ax.legend()
ax.set_title("Data/MC Density")
assert len(ax.mock_calls) == 28 # Updated count due to shared axes functionality
assert len(ax.mock_calls) == 20 # Updated count after removing shared axes iteration
Loading