Skip to content

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

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

Open
anntzer opened this issue Apr 30, 2024 · 3 comments
Open

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

anntzer opened this issue Apr 30, 2024 · 3 comments

Comments

@anntzer
Copy link
Contributor

anntzer commented Apr 30, 2024

Problem

rcParams["axes.titlecolor"] defaults to "auto", i.e. use text.color. On the other hand rcParams["axes.labelcolor"] (the color of the x/ylabels) defaults to "black", i.e. changing rcParams["text.color"] doesn't affect these labels).

Proposed solution

Add support for rcParams["axes.labelcolor"] = "auto", meaning to use the default text color, and make that the default rc value.

For bonus points: rcParams["x/ytick.labelcolor"] currently defaults to "inherit", which means to use the tick color. If we change here the spelling of "use the fallback" to "auto" (#28154), we could use that to also make "auto" mean "use rcParams["text.default"]" instead of rcParams["xtick.color"], which seems actually more consistent, especially if we also switch the rcParams["x/ytick.color"] to defaulting to the defaulf spines color (rcParams["axes.edgecolor"]) -- again, making the tick colors match the spine colors seems more important, to me, than making the tick colors and the ticklabel colors match by default, but ymmv.

@trananso
Copy link
Contributor

trananso commented May 6, 2024

Hi @anntzer, would it make sense to provide support for "auto" in Text.set_color()? Something like this:

--- a/lib/matplotlib/text.py
+++ b/lib/matplotlib/text.py
@@ -987,11 +987,11 @@ class Text(Artist):
         ----------
         color : :mpltype:`color`
         """
-        # "auto" is only supported by axisartist, but we can just let it error
-        # out at draw time for simplicity.
-        if not cbook._str_equal(color, "auto"):
-            mpl.colors._check_color_like(color=color)
-        self._color = color
+        if color == None or cbook._str_lower_equal(color, "auto"):
+            self._color = mpl.rcParams["text.color"]
+        else:
+            self._color = color
+        mpl.colors._check_color_like(color=color)
         self.stale = True

@anntzer
Copy link
Contributor Author

anntzer commented May 7, 2024

I think normal matplotlib semantics would be to just support None.

@trananso
Copy link
Contributor

trananso commented May 7, 2024

I wanted to ask before I created a PR, since my current solution adds a bunch of checks in various parts of the code like this:

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'])

Whereas, supporting label.set_color("auto"), label.set_color(None), etc. could make it easier if we wanted to change the default in the future, and could simplify the code.

trananso@e42586e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants