Skip to content

Commit 67b42d8

Browse files
committed
Don't hide shared "x/y"ticklabels for grids of non-rectilinear axes.
In particular, hiding the "x/y" (i.e. theta/r) ticklabels doesn't make sense for polar axes, and I'd guess likewise for most projections other than the default rectilinear. Try e.g. `subplots(2, 2, subplot_kw=dict(projection="polar"), sharex=True, sharey=True)`.
1 parent cb756d3 commit 67b42d8

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/matplotlib/gridspec.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,13 @@ def subplots(self, *, sharex=False, sharey=False, squeeze=True,
308308
self[row, col], **subplot_kw)
309309

310310
# turn off redundant tick labeling
311-
if sharex in ["col", "all"]:
312-
for ax in axarr.flat:
313-
ax._label_outer_xaxis()
314-
if sharey in ["row", "all"]:
315-
for ax in axarr.flat:
316-
ax._label_outer_yaxis()
311+
if all(ax.name == "rectilinear" for ax in axarr.flat):
312+
if sharex in ["col", "all"]:
313+
for ax in axarr.flat:
314+
ax._label_outer_xaxis()
315+
if sharey in ["row", "all"]:
316+
for ax in axarr.flat:
317+
ax._label_outer_yaxis()
317318

318319
if squeeze:
319320
# Discarding unneeded dimensions that equal 1. If we only have one

lib/matplotlib/tests/test_polar.py

+7
Original file line numberDiff line numberDiff line change
@@ -394,3 +394,10 @@ def test_remove_shared_polar(fig_ref, fig_test):
394394
2, 2, sharey=True, subplot_kw={"projection": "polar"})
395395
for i in [0, 1, 3]:
396396
axs.flat[i].remove()
397+
398+
399+
def test_shared_polar_keeps_ticklabels():
400+
_, axs = plt.subplots(
401+
2, 2, subplot_kw=dict(projection="polar"), sharex=True, sharey=True)
402+
assert axs[0, 1].xaxis._major_tick_kw["label1On"]
403+
assert axs[0, 1].yaxis._major_tick_kw["label1On"]

0 commit comments

Comments
 (0)