Skip to content

[ENH]: axes.labelcolor should use text.color by default #28218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,19 @@ def __init__(
if color is None:
color = mpl.rcParams[f"{name}.color"]

if cbook._str_equal(color, 'auto'):
color = mpl.rcParams["axes.edgecolor"]

if pad is None:
pad = mpl.rcParams[f"{name}.{major_minor}.pad"]
self._base_pad = pad

if labelcolor is None:
labelcolor = mpl.rcParams[f"{name}.labelcolor"]

if cbook._str_equal(labelcolor, 'inherit'):
# inherit from tick color
labelcolor = mpl.rcParams[f"{name}.color"]
if (cbook._str_equal(labelcolor, 'inherit') or
cbook._str_equal(labelcolor, 'auto')):
labelcolor = mpl.rcParams["text.color"]

if labelsize is None:
labelsize = mpl.rcParams[f"{name}.labelsize"]
Expand Down Expand Up @@ -658,11 +661,16 @@ def __init__(self, axes, *, pickradius=15, clear=True):

self._autolabelpos = True

if not cbook._str_lower_equal(mpl.rcParams['axes.labelcolor'], 'auto'):
color = mpl.rcParams['axes.labelcolor']
else:
color = mpl.rcParams['text.color']

self.label = mtext.Text(
np.nan, np.nan,
fontsize=mpl.rcParams['axes.labelsize'],
fontweight=mpl.rcParams['axes.labelweight'],
color=mpl.rcParams['axes.labelcolor'],
color=color
)
self._set_artist_props(self.label)
self.offsetText = mtext.Text(np.nan, np.nan)
Expand Down Expand Up @@ -882,7 +890,10 @@ def clear(self):
self.label._reset_visual_defaults()
# The above resets the label formatting using text rcParams,
# so we then update the formatting using axes rcParams
self.label.set_color(mpl.rcParams['axes.labelcolor'])
if not cbook._str_lower_equal(mpl.rcParams['axes.labelcolor'], 'auto'):
self.label.set_color(mpl.rcParams['axes.labelcolor'])
else:
self.label.set_color(mpl.rcParams['text.color'])
self.label.set_fontsize(mpl.rcParams['axes.labelsize'])
self.label.set_fontweight(mpl.rcParams['axes.labelweight'])
self.offsetText._reset_visual_defaults()
Expand Down Expand Up @@ -2583,10 +2594,11 @@ def _init(self):
)
self.label_position = 'left'

if mpl.rcParams['ytick.labelcolor'] == 'inherit':
tick_color = mpl.rcParams['ytick.color']
else:
tick_color = mpl.rcParams['ytick.labelcolor']
tick_color = mpl.rcParams['ytick.labelcolor']

if (cbook._str_equal(tick_color, 'inherit') or
cbook._str_equal(tick_color, 'auto')):
tick_color = mpl.rcParams["text.color"]

# x in axes coords, y in display coords(!).
self.offsetText.set(
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/mpl-data/matplotlibrc
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@
#axes.labelsize: medium # font size of the x and y labels
#axes.labelpad: 4.0 # space between label and axis
#axes.labelweight: normal # weight of the x and y labels
#axes.labelcolor: black
#axes.labelcolor: auto
#axes.axisbelow: line # draw axis gridlines and ticks:
# - below patches (True)
# - above patches but below lines ('line')
Expand Down Expand Up @@ -481,8 +481,8 @@
#xtick.minor.width: 0.6 # minor tick width in points
#xtick.major.pad: 3.5 # distance to major tick label in points
#xtick.minor.pad: 3.4 # distance to the minor tick label in points
#xtick.color: black # color of the ticks
#xtick.labelcolor: inherit # color of the tick labels or inherit from xtick.color
#xtick.color: auto # color of the ticks
#xtick.labelcolor: auto # color of the tick labels or default to text.color
#xtick.labelsize: medium # font size of the tick labels
#xtick.direction: out # direction: {in, out, inout}
#xtick.minor.visible: False # visibility of minor ticks on x-axis
Expand All @@ -503,8 +503,8 @@
#ytick.minor.width: 0.6 # minor tick width in points
#ytick.major.pad: 3.5 # distance to major tick label in points
#ytick.minor.pad: 3.4 # distance to the minor tick label in points
#ytick.color: black # color of the ticks
#ytick.labelcolor: inherit # color of the tick labels or inherit from ytick.color
#ytick.color: auto # color of the ticks
#ytick.labelcolor: auto # color of the tick labels or default to text.color
#ytick.labelsize: medium # font size of the tick labels
#ytick.direction: out # direction: {in, out, inout}
#ytick.minor.visible: False # visibility of minor ticks on y-axis
Expand Down
16 changes: 11 additions & 5 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ def validate_color_or_auto(s):
return validate_color(s)


def validate_color_inherit_or_auto(s):
if cbook._str_equal(s, 'inherit') or cbook._str_equal(s, 'auto'):
return s
return validate_color(s)


def validate_color_for_prop_cycle(s):
# N-th color cycle syntax can't go into the color cycle.
if isinstance(s, str) and re.match("^C[0-9]$", s):
Expand Down Expand Up @@ -1101,7 +1107,7 @@ def _convert_validator_spec(key, conv):
"axes.labelsize": validate_fontsize, # fontsize of x & y labels
"axes.labelpad": validate_float, # space between label and axis
"axes.labelweight": validate_fontweight, # fontsize of x & y labels
"axes.labelcolor": validate_color, # color of axis label
"axes.labelcolor": validate_color_or_auto, # color of axis label
# use scientific notation if log10 of the axis range is smaller than the
# first or larger than the second
"axes.formatter.limits": _listify_validator(validate_int, n=2),
Expand Down Expand Up @@ -1198,8 +1204,8 @@ def _convert_validator_spec(key, conv):
"xtick.minor.width": validate_float, # minor xtick width in points
"xtick.major.pad": validate_float, # distance to label in points
"xtick.minor.pad": validate_float, # distance to label in points
"xtick.color": validate_color, # color of xticks
"xtick.labelcolor": validate_color_or_inherit, # color of xtick labels
"xtick.color": validate_color_or_auto, # color of xticks
"xtick.labelcolor": validate_color_inherit_or_auto, # color of xtick labels
"xtick.minor.visible": validate_bool, # visibility of minor xticks
"xtick.minor.top": validate_bool, # draw top minor xticks
"xtick.minor.bottom": validate_bool, # draw bottom minor xticks
Expand All @@ -1221,8 +1227,8 @@ def _convert_validator_spec(key, conv):
"ytick.minor.width": validate_float, # minor ytick width in points
"ytick.major.pad": validate_float, # distance to label in points
"ytick.minor.pad": validate_float, # distance to label in points
"ytick.color": validate_color, # color of yticks
"ytick.labelcolor": validate_color_or_inherit, # color of ytick labels
"ytick.color": validate_color_or_auto, # color of yticks
"ytick.labelcolor": validate_color_inherit_or_auto, # color of ytick labels
"ytick.minor.visible": validate_bool, # visibility of minor yticks
"ytick.minor.left": validate_bool, # draw left minor yticks
"ytick.minor.right": validate_bool, # draw right minor yticks
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/rcsetup.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ def validate_fonttype(s: Any) -> int: ...
_auto_backend_sentinel: object

def validate_backend(s: Any) -> str: ...
def validate_color_or_inherit(s: Any) -> Literal["inherit"] | ColorType: ...
def validate_color_or_inherit(s: Any) -> ColorType | Literal["inherit"]: ...
def validate_color_or_auto(s: Any) -> ColorType | Literal["auto"]: ...
def validate_color_inherit_or_auto(s: Any) -> ColorType | Literal["inherit"] | Literal["auto"]: ...
def validate_color_for_prop_cycle(s: Any) -> ColorType: ...
def validate_color(s: Any) -> ColorType: ...
def validate_colorlist(s: Any) -> list[ColorType]: ...
Expand Down
Loading