From 67b42d8525d592848d2513f8024f1477d3bce25a Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 16 Apr 2021 22:18:05 +0200 Subject: [PATCH] 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)`. --- lib/matplotlib/gridspec.py | 13 +++++++------ lib/matplotlib/tests/test_polar.py | 7 +++++++ 2 files changed, 14 insertions(+), 6 deletions(-) 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"] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy