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

Skip to content

Commit bc5a692

Browse files
committed
Issue error message if tickloc/ticklabelloc are invalid
1 parent 219e4b2 commit bc5a692

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

‎proplot/axes/cartesian.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
xloc, yloc : optional
6565
Shorthands for `xspineloc`, `yspineloc`.
6666
xspineloc, yspineloc : {'bottom', 'top', 'left', 'right', \
67-
'both', 'neither', 'none', 'center', 'zero'}, optional
68-
The x and y axis spine locations. Propagates to `tickloc` unless specified
69-
otherwise (if not ``'center'`` or ``'zero'``).
67+
'both', 'neither', 'none', 'zero', 'center'} or 2-tuple, optional
68+
The x and y spine locations. Applied with `~matplotlib.spines.Spine.set_position`.
69+
Propagates to `tickloc` unless specified otherwise.
7070
xtickloc, ytickloc \
7171
: {'bottom', 'top', 'left', 'right', 'both', 'neither', 'none'}, optional
7272
Which x and y axis spines should have major and minor tick marks. Inherits from
@@ -735,12 +735,17 @@ def _update_locs(
735735
# The tick and tick label sides for Cartesian axes
736736
kw = {}
737737
sides = ('bottom', 'top') if x == 'x' else ('left', 'right')
738+
sides_map = {'both': sides, 'neither': (), 'none': (), None: None}
738739
sides_active = tuple(side for side in sides if self.spines[side].get_visible())
739-
sides_dict = {None: None, 'both': sides, 'none': (), 'neither': ()}
740740

741741
# The tick side(s)
742742
# NOTE: Silently forbids adding ticks to sides with invisible spines
743-
ticklocs = sides_dict.get(tickloc, (tickloc,))
743+
ticklocs = sides_map.get(tickloc, (tickloc,))
744+
if ticklocs and any(loc not in sides for loc in ticklocs):
745+
raise ValueError(
746+
f'Invalid tick mark location {tickloc!r}. Options are '
747+
+ ', '.join(map(repr, sides + tuple(sides_map))) + '.'
748+
)
744749
if ticklocs is not None:
745750
kw.update({side: side in ticklocs for side in sides})
746751
kw.update(
@@ -751,7 +756,12 @@ def _update_locs(
751756

752757
# The tick label side(s). Make sure these only appear where ticks are
753758
# NOTE: Silently forbids adding labels to sides with invisible ticks or spines
754-
ticklabellocs = sides_dict.get(ticklabelloc, (ticklabelloc,))
759+
ticklabellocs = sides_map.get(ticklabelloc, (ticklabelloc,))
760+
if ticklabellocs and any(loc not in sides for loc in ticklabellocs):
761+
raise ValueError(
762+
f'Invalid tick label location {ticklabelloc!r}. Options are '
763+
+ ', '.join(map(repr, sides + tuple(sides_map))) + '.'
764+
)
755765
if ticklabellocs is not None:
756766
kw.update({'label' + side: (side in ticklabellocs) for side in sides})
757767
kw.update(

0 commit comments

Comments
 (0)