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

Skip to content

Commit 96a37e5

Browse files
committed
Add [xy]offsetloc keywords, follow other locs by default
1 parent 1fa90f8 commit 96a37e5

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

‎proplot/axes/cartesian.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,22 @@
5252
``xscale=('cutoff', 100, 2)`` applies a `~proplot.scale.CutoffScale`.
5353
xscale_kw, yscale_kw : dict-like, optional
5454
The x and y axis scale settings. Passed to `~proplot.scale.Scale`.
55-
xspineloc, yspineloc \
56-
: {'bottom', 'top', 'left', 'right', 'both', 'neither', 'center', 'zero'}, optional
55+
xspineloc, yspineloc : {'bottom', 'top', 'left', 'right', \
56+
'both', 'neither', 'none', 'center', 'zero'}, optional
5757
The x and y axis spine locations.
5858
xtickloc, ytickloc \
59-
: {'bottom', 'top', 'left', 'right', 'both', 'neither'}, optional
59+
: {'bottom', 'top', 'left', 'right', 'both', 'neither', 'none'}, optional
6060
Which x and y axis spines should have major and minor tick marks.
6161
xticklabelloc, yticklabelloc \
62-
: {'bottom', 'top', 'left', 'right', 'both', 'neither'}, optional
62+
: {'bottom', 'top', 'left', 'right', 'both', 'neither', 'none'}, optional
6363
Which x and y axis spines should have major tick labels. Default
6464
behavior is to inherit this from `xtickloc` and `ytickloc`.
6565
xlabelloc, ylabelloc : {'bottom', 'top', 'left', 'right'}, optional
6666
Which x and y axis spines should have axis labels. Default
6767
behavior is to inherit this from `xticklabelloc` and `yticklabelloc`.
68+
xoffsetloc, yoffsetloc : {'bottom', 'top', 'left', 'right'}, optional
69+
Which x and y axis spines should have the axis offset indicator. Default
70+
behavior is to inherit this from `xticklabelloc` and `yticklabelloc`.
6871
xtickdir, ytickdir, tickdir : {'out', 'in', 'inout'}
6972
Direction that major and minor tick marks point for the x and y axis.
7073
Use `tickdir` to control both.
@@ -702,7 +705,9 @@ def _update_spines(self, x, *, loc=None, bounds=None):
702705
if bounds is not None:
703706
spine.set_bounds(*bounds)
704707

705-
def _update_locs(self, x, *, tickloc=None, ticklabelloc=None, labelloc=None):
708+
def _update_locs(
709+
self, x, *, tickloc=None, ticklabelloc=None, labelloc=None, offsetloc=None
710+
):
706711
"""
707712
Update the tick, tick label, and axis label locations.
708713
"""
@@ -713,12 +718,18 @@ def _update_locs(self, x, *, tickloc=None, ticklabelloc=None, labelloc=None):
713718
sides_dict = {None: None, 'both': sides, 'none': (), 'neither': ()}
714719

715720
# The tick side(s)
721+
# NOTE: Silently forbids adding ticks to sides with invisible spines
716722
ticklocs = sides_dict.get(tickloc, (tickloc,))
717723
if ticklocs is not None:
718724
kw.update({side: side in ticklocs for side in sides})
719-
kw.update({side: False for side in sides if side not in sides_active})
725+
kw.update(
726+
{
727+
side: False for side in sides if side not in sides_active
728+
}
729+
)
720730

721731
# The tick label side(s). Make sure these only appear where ticks are
732+
# NOTE: Silently forbids adding labels to sides with invisible ticks or spines
722733
ticklabellocs = sides_dict.get(ticklabelloc, (ticklabelloc,))
723734
if ticklabellocs is not None:
724735
kw.update({'label' + side: (side in ticklabellocs) for side in sides})
@@ -731,21 +742,25 @@ def _update_locs(self, x, *, tickloc=None, ticklabelloc=None, labelloc=None):
731742
)
732743

733744
# The axis label side(s)
734-
if labelloc is None:
735-
if ticklocs is not None:
736-
options = tuple(_ for _ in sides if _ in ticklocs and _ in sides_active)
737-
if len(options) == 1:
738-
labelloc = options[0]
745+
# NOTE: Silently forbids adding labels and offsets to sides with missing spines
746+
if ticklocs is not None:
747+
options = tuple(_ for _ in sides if _ in ticklocs and _ in sides_active)
748+
if len(options) == 1:
749+
labelloc = _not_none(labelloc, options[0])
750+
offsetloc = _not_none(offsetloc, options[0])
739751
if labelloc is not None and labelloc not in sides:
740752
raise ValueError(
741753
f'Invalid label location {labelloc!r}. Options are '
742754
+ ', '.join(map(repr, sides)) + '.'
743755
)
744756

745757
# Apply the tick, tick label, and label locations
758+
axis = getattr(self, x + 'axis')
746759
self.tick_params(axis=x, which='both', **kw)
747760
if labelloc is not None:
748-
getattr(self, x + 'axis').set_label_position(labelloc)
761+
axis.set_label_position(labelloc)
762+
if offsetloc is not None:
763+
axis.set_offset_position(offsetloc)
749764

750765
@warnings._rename_kwargs('0.9', xloc='xspineloc', yloc='yspineloc')
751766
@docstring._snippet_manager
@@ -756,6 +771,7 @@ def format(
756771
xspineloc=None, yspineloc=None,
757772
xtickloc=None, ytickloc=None, fixticks=False,
758773
xlabelloc=None, ylabelloc=None,
774+
xoffsetloc=None, yoffsetloc=None,
759775
xticklabelloc=None, yticklabelloc=None,
760776
xtickdir=None, ytickdir=None,
761777
xgrid=None, ygrid=None,
@@ -863,10 +879,12 @@ def format(
863879
xticklabelloc = _not_none(xticklabelloc, xtickloc)
864880
if xticklabelloc in ('bottom', 'top'):
865881
xlabelloc = _not_none(xlabelloc, xticklabelloc)
882+
xoffsetloc = _not_none(xoffsetloc, xticklabelloc)
866883
if ytickloc != 'both': # then infer others
867884
yticklabelloc = _not_none(yticklabelloc, ytickloc)
868885
if yticklabelloc in ('left', 'right'):
869886
ylabelloc = _not_none(ylabelloc, yticklabelloc)
887+
ylabelloc = _not_none(yoffsetloc, yticklabelloc)
870888

871889
# Loop over axes
872890
for (
@@ -877,6 +895,7 @@ def format(
877895
margin, bounds,
878896
tickloc, spineloc,
879897
ticklabelloc, labelloc,
898+
offsetloc,
880899
grid, gridminor,
881900
tickminor, minorlocator,
882901
min_, max_, lim,
@@ -896,6 +915,7 @@ def format(
896915
(xmargin, ymargin), (xbounds, ybounds),
897916
(xtickloc, ytickloc), (xspineloc, yspineloc),
898917
(xticklabelloc, yticklabelloc), (xlabelloc, ylabelloc),
918+
(xoffsetloc, yoffsetloc),
899919
(xgrid, ygrid), (xgridminor, ygridminor),
900920
(xtickminor, ytickminor), (xminorlocator, yminorlocator),
901921
(xmin, ymin), (xmax, ymax), (xlim, ylim),
@@ -934,7 +954,8 @@ def format(
934954

935955
# Axis tick settings
936956
self._update_locs(
937-
x, tickloc=tickloc, ticklabelloc=ticklabelloc, labelloc=labelloc
957+
x, tickloc=tickloc, ticklabelloc=ticklabelloc,
958+
labelloc=labelloc, offsetloc=offsetloc,
938959
)
939960
self._update_rotation(
940961
x, rotation=rotation

0 commit comments

Comments
 (0)