Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c03610

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 5799a5c commit 4c03610

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/matplotlib/gridspec.py

Lines changed: 7 additions & 6 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,10 @@ def test_thetalim_valid_invalid():
348348
with pytest.raises(ValueError,
349349
match='The angle range must be <= 360 degrees'):
350350
ax.set_thetalim(thetamin=800, thetamax=400)
351+
352+
353+
def test_shared_polar_keeps_ticklabels():
354+
_, axs = plt.subplots(
355+
2, 2, subplot_kw=dict(projection="polar"), sharex=True, sharey=True)
356+
assert axs[0, 1].xaxis._major_tick_kw["label1On"]
357+
assert axs[0, 1].yaxis._major_tick_kw["label1On"]

0 commit comments

Comments
 (0)