diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 01c1a1329c4a..d78582726927 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1173,14 +1173,16 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False, if sharex in ["col", "all"]: # turn off all but the bottom row for ax in axarr[:-1, :].flat: - for label in ax.get_xticklabels(): - label.set_visible(False) + ax.xaxis.set_tick_params(which='both', + label1On=False, label2On=False) ax.xaxis.offsetText.set_visible(False) if sharey in ["row", "all"]: # turn off all but the first column for ax in axarr[:, 1:].flat: - for label in ax.get_yticklabels(): + for label in ax.get_yticklabels(which='both'): label.set_visible(False) + ax.yaxis.set_tick_params(which='both', + label1On=False, label2On=False) ax.yaxis.offsetText.set_visible(False) if squeeze: diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index d2c8b7aef68d..5f2d3b1b2a82 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -298,3 +298,24 @@ def test_invalid_figure_size(): with pytest.raises(ValueError): fig.add_axes((.1, .1, .5, np.nan)) + + +def test_subplots_shareax_loglabels(): + fig, ax_arr = plt.subplots(2, 2, sharex=True, sharey=True, squeeze=False) + for ax in ax_arr.flatten(): + ax.plot([10, 20, 30], [10, 20, 30]) + + ax.set_yscale("log") + ax.set_xscale("log") + + for ax in ax_arr[0, :]: + assert 0 == len(ax.xaxis.get_ticklabels(which='both')) + + for ax in ax_arr[1, :]: + assert 0 < len(ax.xaxis.get_ticklabels(which='both')) + + for ax in ax_arr[:, 1]: + assert 0 == len(ax.yaxis.get_ticklabels(which='both')) + + for ax in ax_arr[:, 0]: + assert 0 < len(ax.yaxis.get_ticklabels(which='both'))
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: