Skip to content

Commit 1c58bfc

Browse files
committed
Fix issue with coordinate spine pos not updating tick/label pos
1 parent 20f17fe commit 1c58bfc

1 file changed

Lines changed: 36 additions & 17 deletions

File tree

proplot/axes/cartesian.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,31 @@ def _fix_ticks(self, x, fixticks=False):
467467
locator = constructor.Locator(skipticks(locator()))
468468
axis.set_minor_locator(locator)
469469

470+
def _get_spine_side(self, x, loc):
471+
"""
472+
Get the spine side implied by the input location or position. This
473+
propagates to tick mark, tick label, and axis label positions.
474+
"""
475+
sides = ('bottom', 'top') if x == 'x' else ('left', 'right')
476+
centers = ('zero', 'center')
477+
options = (*sides, 'both', 'neither', 'none')
478+
if np.iterable(loc) and len(loc) == 2 and loc[0] in ('axes', 'data'):
479+
if loc[0] == 'axes':
480+
side = sides[int(loc[1] > 0.5)]
481+
elif loc[0] == 'data':
482+
lim = getattr(self, f'get_{x}lim')()
483+
side = sides[int(loc[1] > lim[0] + 0.5 * (lim[1] - lim[0]))]
484+
elif loc in centers:
485+
side = sides[0]
486+
elif loc is None or loc in options:
487+
side = loc
488+
else:
489+
raise ValueError(
490+
f'Invalid {x} spine location {loc!r}. Options are: '
491+
+ ', '.join(map(repr, (*options, *centers)))
492+
)
493+
return side
494+
470495
def _is_panel_group_member(self, other):
471496
"""
472497
Return whether the axes belong in a panel sharing stack..
@@ -739,25 +764,17 @@ def _update_spines(self, x, *, loc=None, bounds=None):
739764
"""
740765
# Iterate over spines associated with this axis
741766
sides = ('bottom', 'top') if x == 'x' else ('left', 'right')
742-
vboth = all(self.spines[side].get_visible() for side in sides) # both visible
743-
pside = sides[0] # side for spine.set_position()
744-
if np.iterable(loc) and len(loc) == 2 and loc[0] in ('axes', 'data'):
745-
if loc[0] == 'data':
746-
lim = getattr(self, f'get_{x}lim')()
747-
center = lim[0] + 0.5 * (lim[1] - lim[0])
748-
else:
749-
center = 0.5
750-
pside = sides[int(loc[1] > center)]
767+
pside = self._get_spine_side(x, loc) # side for set_position()
768+
if bounds is not None and all(self.spines[s].get_visible() for s in sides):
769+
loc = _not_none(loc, sides[0])
751770
for side in sides:
752771
# Change default spine location from 'both' to the first relevant
753772
# side if the user passes 'bounds'.
754773
spine = self.spines[side]
755-
if vboth and bounds is not None:
756-
loc = _not_none(loc, sides[0])
757774
# Eliminate sides
758775
if loc is None:
759776
pass
760-
elif loc == 'neither':
777+
elif loc == 'neither' or loc == 'none':
761778
spine.set_visible(False)
762779
elif loc == 'both':
763780
spine.set_visible(True)
@@ -769,14 +786,14 @@ def _update_spines(self, x, *, loc=None, bounds=None):
769786
elif pside != side:
770787
spine.set_visible(False)
771788
else:
789+
spine.set_visible(True)
772790
try:
773791
spine.set_position(loc)
774792
except ValueError:
775793
raise ValueError(
776794
f'Invalid {x} spine location {loc!r}. Options are: '
777795
+ ', '.join(map(repr, (*sides, 'both', 'neither'))) + '.'
778796
)
779-
spine.set_visible(True)
780797
# Apply spine bounds
781798
if bounds is not None:
782799
spine.set_bounds(*bounds)
@@ -990,10 +1007,12 @@ def format(
9901007
# want this sometimes! Same goes for spines!
9911008
xspineloc = _not_none(xloc=xloc, xspineloc=xspineloc)
9921009
yspineloc = _not_none(yloc=yloc, yspineloc=yspineloc)
993-
if isinstance(xspineloc, str) and xspineloc not in ('zero', 'center'):
994-
xtickloc = _not_none(xtickloc, xspineloc)
995-
if isinstance(yspineloc, str) and yspineloc not in ('zero', 'center'):
996-
ytickloc = _not_none(ytickloc, yspineloc)
1010+
xside = self._get_spine_side('x', xspineloc)
1011+
yside = self._get_spine_side('y', yspineloc)
1012+
if xside is not None and xside not in ('zero', 'center'):
1013+
xtickloc = _not_none(xtickloc, xside)
1014+
if yside is not None and yside not in ('zero', 'center'):
1015+
ytickloc = _not_none(ytickloc, yside)
9971016
if xtickloc != 'both': # then infer others
9981017
xticklabelloc = _not_none(xticklabelloc, xtickloc)
9991018
if xticklabelloc in ('bottom', 'top'):

0 commit comments

Comments
 (0)