Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c593c2c

Browse filesBrowse files
committed
Fix removal of shared polar axes.
There's really two separate fixes here: - Move isDefault_{maj,min}{loc,fmt} tracking to the Ticker instances, where they logically belong (note the previous need to additionally track them manually on axes removal, when that info was tracked on the Axis). This has the side effect of fixing removal of sharex'd polar axes, as ThetaLocators rely on _AxisWrappers which don't have that isDefault attribute. (Note that the patch would have resulted in a net decrease of lines of code if it didn't need to maintain backcompat on isDefault_foos). - Ensure that RadialLocator correctly propagates Axis information to the linear locator it wraps (consistently with ThetaLocator), so that when an axes is removed the wrapped linear locator doesn't stay pointing at an obsolete axes. This, together with the first patch, fixes removal of sharey'd polar axes.
1 parent a94acb3 commit c593c2c
Copy full SHA for c593c2c

File tree

Expand file treeCollapse file tree

4 files changed

+56
-27
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+56
-27
lines changed

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,8 @@ class Ticker:
552552
def __init__(self):
553553
self._locator = None
554554
self._formatter = None
555+
self._locator_is_default = True
556+
self._formatter_is_default = True
555557

556558
@property
557559
def locator(self):
@@ -689,6 +691,38 @@ def __init__(self, axes, pickradius=15):
689691
self.clear()
690692
self._set_scale('linear')
691693

694+
@property
695+
def isDefault_majloc(self):
696+
return self.major._locator_is_default
697+
698+
@isDefault_majloc.setter
699+
def isDefault_majloc(self, value):
700+
self.major._locator_is_default = value
701+
702+
@property
703+
def isDefault_majfmt(self):
704+
return self.major._formatter_is_default
705+
706+
@isDefault_majfmt.setter
707+
def isDefault_majfmt(self, value):
708+
self.major._formatter_is_default = value
709+
710+
@property
711+
def isDefault_minloc(self):
712+
return self.minor._locator_is_default
713+
714+
@isDefault_minloc.setter
715+
def isDefault_minloc(self, value):
716+
self.minor._locator_is_default = value
717+
718+
@property
719+
def isDefault_minfmt(self):
720+
return self.minor._formatter_is_default
721+
722+
@isDefault_minfmt.setter
723+
def isDefault_minfmt(self, value):
724+
self.minor._formatter_is_default = value
725+
692726
# During initialization, Axis objects often create ticks that are later
693727
# unused; this turns out to be a very slow step. Instead, use a custom
694728
# descriptor to make the tick lists lazy and instantiate them as needed.

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+4-27Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -916,33 +916,10 @@ def _reset_locators_and_formatters(axis):
916916
# Set the formatters and locators to be associated with axis
917917
# (where previously they may have been associated with another
918918
# Axis instance)
919-
#
920-
# Because set_major_formatter() etc. force isDefault_* to be False,
921-
# we have to manually check if the original formatter was a
922-
# default and manually set isDefault_* if that was the case.
923-
majfmt = axis.get_major_formatter()
924-
isDefault = majfmt.axis.isDefault_majfmt
925-
axis.set_major_formatter(majfmt)
926-
if isDefault:
927-
majfmt.axis.isDefault_majfmt = True
928-
929-
majloc = axis.get_major_locator()
930-
isDefault = majloc.axis.isDefault_majloc
931-
axis.set_major_locator(majloc)
932-
if isDefault:
933-
majloc.axis.isDefault_majloc = True
934-
935-
minfmt = axis.get_minor_formatter()
936-
isDefault = majloc.axis.isDefault_minfmt
937-
axis.set_minor_formatter(minfmt)
938-
if isDefault:
939-
minfmt.axis.isDefault_minfmt = True
940-
941-
minloc = axis.get_minor_locator()
942-
isDefault = majloc.axis.isDefault_minloc
943-
axis.set_minor_locator(minloc)
944-
if isDefault:
945-
minloc.axis.isDefault_minloc = True
919+
axis.get_major_formatter().set_axis(axis)
920+
axis.get_major_locator().set_axis(axis)
921+
axis.get_minor_formatter().set_axis(axis)
922+
axis.get_minor_locator().set_axis(axis)
946923

947924
def _break_share_link(ax, grouper):
948925
siblings = grouper.get_siblings(ax)

‎lib/matplotlib/projections/polar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/projections/polar.py
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,9 @@ def __init__(self, base, axes=None):
425425
self.base = base
426426
self._axes = axes
427427

428+
def set_axis(self, axis):
429+
self.base.set_axis(axis)
430+
428431
def __call__(self):
429432
# Ensure previous behaviour with full circle non-annular views.
430433
if self._axes:

‎lib/matplotlib/tests/test_polar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_polar.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,3 +379,18 @@ def test_axvspan():
379379
ax = plt.subplot(projection="polar")
380380
span = plt.axvspan(0, np.pi/4)
381381
assert span.get_path()._interpolation_steps > 1
382+
383+
384+
@check_figures_equal(extensions=["png"])
385+
def test_remove_shared_polar(fig_ref, fig_test):
386+
# Removing shared polar axes used to crash. Test removing them, keeping in
387+
# both cases just the lower left axes of a grid to avoid running into a
388+
# separate issue (now being fixed) of ticklabel visibility for shared axes.
389+
axs = fig_ref.subplots(
390+
2, 2, sharex=True, subplot_kw={"projection": "polar"})
391+
for i in [0, 1, 3]:
392+
axs.flat[i].remove()
393+
axs = fig_test.subplots(
394+
2, 2, sharey=True, subplot_kw={"projection": "polar"})
395+
for i in [0, 1, 3]:
396+
axs.flat[i].remove()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.