Skip to content

Commit 68cba1a

Browse files
committed
Add '[x|y]tick[label|]color' format() keywords
1 parent 8ecbf0b commit 68cba1a

3 files changed

Lines changed: 38 additions & 15 deletions

File tree

proplot/axes/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,12 @@ def _get_tick_props(axis=None, which='major'):
980980
# Tick properties obtained with rc.category
981981
# NOTE: This loads 'size', 'width', 'pad', 'bottom', and 'top'
982982
axis = _not_none(axis, 'x')
983-
kwticks = rc.category(axis + 'tick.' + which, context=True)
983+
kwticks = rc.category(f'{axis}tick.{which}', context=True)
984984
kwticks.pop('visible', None)
985+
for key in ('color', 'direction'):
986+
value = rc.find(f'{axis}tick.{key}', context=True)
987+
if value is not None:
988+
kwticks[key] = value
985989
return kwticks
986990

987991
def _get_size_inches(self):

proplot/axes/cartesian.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,17 @@
160160
Line width for the x and y axis spines and major ticks.
161161
Use `linewidth` to set both at once.
162162
xcolor, ycolor, color : color-spec, optional
163-
Color for the x and y axis spines, ticks, tick labels, and
164-
axis labels. Use `color` to set both at once.
163+
Color for the x and y axis spines, ticks, tick labels, and axis
164+
labels. Use `color` to set both at once.
165+
xtickcolor, ytickcolor, tickcolor : color-spec, optional
166+
Color for the x and y axis ticks. Inherits from `color` by
167+
default. Use `tickcolor` to set both at once.
168+
xticklabelcolor, yticklabelcolor, ticklabelcolor : color-spec, optional
169+
Color for the x and y tick labels. Inherits from `color` by
170+
default. Use `ticklabelcolor` to set both at once.
171+
xlabelcolor, ylabelcolor, labelcolor : color-spec, optional
172+
Color for the x and y axis labels. Inherits from `color` by
173+
default. Use `labelcolor` to set both at once.
165174
xgridcolor, ygridcolor, gridcolor : color-spec, optional
166175
Color for the x and y axis major and minor gridlines.
167176
Use `gridcolor` to set both at once.
@@ -847,6 +856,8 @@ def format(
847856
xticklenratio=None, yticklenratio=None,
848857
xlinewidth=None, ylinewidth=None,
849858
xcolor=None, ycolor=None, color=None, # special case (see below)
859+
xtickcolor=None, ytickcolor=None,
860+
xticklabelcolor=None, yticklabelcolor=None,
850861
xlabelcolor=None, ylabelcolor=None,
851862
xgridcolor=None, ygridcolor=None,
852863
xlabel_kw=None, ylabel_kw=None,
@@ -898,13 +909,18 @@ def format(
898909
xminorlocator_kw = xminorlocator_kw or {}
899910
yminorlocator_kw = yminorlocator_kw or {}
900911

901-
# Special case: normally we rely on rc settings like 'grid', 'labelpad',
902-
# etc. when x or y is not specified but a bald 'color' rc setting is
903-
# too vague. So we apply 'color' right here.
912+
# Color keyword arguments. Inherit from 'color' when necessary
904913
xcolor = _not_none(xcolor, color)
905914
ycolor = _not_none(ycolor, color)
906-
xlabelcolor = _not_none(xlabelcolor, xcolor)
907-
ylabelcolor = _not_none(ylabelcolor, ycolor)
915+
if 'tick.color' not in rc_kw:
916+
xtickcolor = _not_none(xtickcolor, xcolor)
917+
ytickcolor = _not_none(ytickcolor, ycolor)
918+
if 'tick.labelcolor' not in rc_kw:
919+
xticklabelcolor = _not_none(xticklabelcolor, xcolor)
920+
yticklabelcolor = _not_none(yticklabelcolor, ycolor)
921+
if 'label.color' not in rc_kw:
922+
xlabelcolor = _not_none(xlabelcolor, xcolor)
923+
ylabelcolor = _not_none(ylabelcolor, ycolor)
908924

909925
# Flexible keyword args, declare defaults
910926
xmargin = _not_none(xmargin, rc.find('axes.margin', context=True))
@@ -950,6 +966,7 @@ def format(
950966
labelpad, ticklabelpad,
951967
color, linewidth,
952968
gridcolor, labelcolor,
969+
tickcolor, ticklabelcolor,
953970
ticklen, ticklenratio,
954971
margin, bounds,
955972
tickloc, spineloc,
@@ -971,6 +988,7 @@ def format(
971988
(xlabelpad, ylabelpad), (xticklabelpad, yticklabelpad),
972989
(xcolor, ycolor), (xlinewidth, ylinewidth),
973990
(xgridcolor, ygridcolor), (xlabelcolor, ylabelcolor),
991+
(xtickcolor, ytickcolor), (xticklabelcolor, yticklabelcolor),
974992
(xticklen, yticklen), (xticklenratio, yticklenratio),
975993
(xmargin, ymargin), (xbounds, ybounds),
976994
(xtickloc, ytickloc), (xspineloc, yspineloc),
@@ -1023,9 +1041,8 @@ def format(
10231041
self._update_ticks(
10241042
x, grid=grid, gridminor=gridminor,
10251043
ticklen=ticklen, ticklenratio=ticklenratio,
1026-
tickcolor=color, gridcolor=gridcolor,
1027-
tickdir=tickdir, ticklabeldir=ticklabeldir,
1028-
labelpad=ticklabelpad,
1044+
tickdir=tickdir, labeldir=ticklabeldir, labelpad=ticklabelpad,
1045+
tickcolor=tickcolor, gridcolor=gridcolor, labelcolor=ticklabelcolor,
10291046
)
10301047

10311048
# Axis label settings

proplot/axes/shared.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ def _update_background(self, x=None, **kwargs):
5050
self.tick_params(axis=axis, which='minor', width=linewidth * ratio, **kw)
5151

5252
def _update_ticks(
53-
self, x, *, grid=None, gridminor=None, gridcolor=None, gridpad=None,
54-
ticklen=None, ticklenratio=None, tickdir=None, ticklabeldir=None,
55-
tickcolor=None, labelpad=None
53+
self, x, *, grid=None, gridminor=None, gridpad=None, gridcolor=None,
54+
ticklen=None, ticklenratio=None, tickdir=None, tickcolor=None,
55+
labeldir=None, labelpad=None, labelcolor=None,
5656
):
5757
"""
5858
Update the gridlines and labels. Set `gridpad` to ``True`` to use grid padding.
@@ -76,6 +76,8 @@ def _update_ticks(
7676
kwtext.setdefault('labelcolor', tickcolor)
7777
else:
7878
kwtext['labelcolor'] = tickcolor
79+
if labelcolor is not None:
80+
kwtext['labelcolor'] = labelcolor
7981
if ticklen is not None or ticklenratio is not None:
8082
if ticklen is None: # must use private API so add graceful fallback
8183
kwaxis = getattr(axis, f'_{which}_tick_kw', {})
@@ -108,7 +110,7 @@ def _update_ticks(
108110
kwdir = {}
109111
if tickdir == 'in': # ticklabels should be much closer
110112
kwdir['pad'] = 1.0
111-
if ticklabeldir == 'in': # put tick labels inside the plot
113+
if labeldir == 'in': # put tick labels inside the plot
112114
tickdir = 'in'
113115
kwdir['pad'] = (
114116
- rc[f'{x}tick.major.size']

0 commit comments

Comments
 (0)