diff --git a/src/mplhep/comparison_plotters.py b/src/mplhep/comparison_plotters.py index 10afe7d8..10175148 100644 --- a/src/mplhep/comparison_plotters.py +++ b/src/mplhep/comparison_plotters.py @@ -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 @@ -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 diff --git a/src/mplhep/plot.py b/src/mplhep/plot.py index c77c3ee8..11ce030a 100644 --- a/src/mplhep/plot.py +++ b/src/mplhep/plot.py @@ -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() diff --git a/tests/baseline/1d_comparison_asymmetry.png b/tests/baseline/1d_comparison_asymmetry.png index 383dbfce..922fbb1f 100644 Binary files a/tests/baseline/1d_comparison_asymmetry.png and b/tests/baseline/1d_comparison_asymmetry.png differ diff --git a/tests/baseline/1d_comparison_difference.png b/tests/baseline/1d_comparison_difference.png index 050b5681..3206ea02 100644 Binary files a/tests/baseline/1d_comparison_difference.png and b/tests/baseline/1d_comparison_difference.png differ diff --git a/tests/baseline/1d_comparison_pull.png b/tests/baseline/1d_comparison_pull.png index 00db5cf4..7937bcaf 100644 Binary files a/tests/baseline/1d_comparison_pull.png and b/tests/baseline/1d_comparison_pull.png differ diff --git a/tests/baseline/1d_comparison_ratio.png b/tests/baseline/1d_comparison_ratio.png index 70b7e066..6e1ba833 100644 Binary files a/tests/baseline/1d_comparison_ratio.png and b/tests/baseline/1d_comparison_ratio.png differ diff --git a/tests/baseline/1d_comparison_relative_difference.png b/tests/baseline/1d_comparison_relative_difference.png index e231ffa1..942ab5d9 100644 Binary files a/tests/baseline/1d_comparison_relative_difference.png and b/tests/baseline/1d_comparison_relative_difference.png differ diff --git a/tests/baseline/1d_comparison_split_ratio.png b/tests/baseline/1d_comparison_split_ratio.png index 7d639a08..e83fb98f 100644 Binary files a/tests/baseline/1d_comparison_split_ratio.png and b/tests/baseline/1d_comparison_split_ratio.png differ diff --git a/tests/baseline/model_all_comparisons_no_model_unc.png b/tests/baseline/model_all_comparisons_no_model_unc.png index 58af7f7b..a07348f6 100644 Binary files a/tests/baseline/model_all_comparisons_no_model_unc.png and b/tests/baseline/model_all_comparisons_no_model_unc.png differ diff --git a/tests/from_issues/baseline/test_issue_594.png b/tests/from_issues/baseline/test_issue_594.png index 5c1054c2..2b85a3b6 100644 Binary files a/tests/from_issues/baseline/test_issue_594.png and b/tests/from_issues/baseline/test_issue_594.png differ diff --git a/tests/test_mock.py b/tests/test_mock.py index 2bf15735..cf5fd209 100644 --- a/tests/test_mock.py +++ b/tests/test_mock.py @@ -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]), @@ -101,7 +101,7 @@ 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() @@ -109,7 +109,7 @@ def test_histplot_real(mock_matplotlib): 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( @@ -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( @@ -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