diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index 47afdda51c41..ecdb97dbf5f1 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -308,12 +308,13 @@ def subplots(self, *, sharex=False, sharey=False, squeeze=True, self[row, col], **subplot_kw) # turn off redundant tick labeling - if sharex in ["col", "all"]: - for ax in axarr.flat: - ax._label_outer_xaxis() - if sharey in ["row", "all"]: - for ax in axarr.flat: - ax._label_outer_yaxis() + if all(ax.name == "rectilinear" for ax in axarr.flat): + if sharex in ["col", "all"]: + for ax in axarr.flat: + ax._label_outer_xaxis() + if sharey in ["row", "all"]: + for ax in axarr.flat: + ax._label_outer_yaxis() if squeeze: # Discarding unneeded dimensions that equal 1. If we only have one diff --git a/lib/matplotlib/tests/test_polar.py b/lib/matplotlib/tests/test_polar.py index 73eea36e46a9..b6fc7ffb8778 100644 --- a/lib/matplotlib/tests/test_polar.py +++ b/lib/matplotlib/tests/test_polar.py @@ -394,3 +394,10 @@ def test_remove_shared_polar(fig_ref, fig_test): 2, 2, sharey=True, subplot_kw={"projection": "polar"}) for i in [0, 1, 3]: axs.flat[i].remove() + + +def test_shared_polar_keeps_ticklabels(): + _, axs = plt.subplots( + 2, 2, subplot_kw=dict(projection="polar"), sharex=True, sharey=True) + assert axs[0, 1].xaxis._major_tick_kw["label1On"] + assert axs[0, 1].yaxis._major_tick_kw["label1On"]