Title: [Bug]: rcParams["legend.labelcolor"] treats "none" and "None" differently · Issue #28153 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: rcParams["legend.labelcolor"] treats "none" and "None" differently · Issue #28153 · matplotlib/matplotlib
X Title: [Bug]: rcParams["legend.labelcolor"] treats "none" and "None" differently · Issue #28153 · matplotlib/matplotlib
Description: Bug summary The "standard" matplotlib color semantics is that the strings "none" and "None" both mean fully transparent (as can be checked by mpl.colors.to_rgba); the object None can sometimes be used to mark a fallback. Because the matp...
Open Graph Description: Bug summary The "standard" matplotlib color semantics is that the strings "none" and "None" both mean fully transparent (as can be checked by mpl.colors.to_rgba); the object None can sometimes be u...
X Description: Bug summary The "standard" matplotlib color semantics is that the strings "none" and "None" both mean fully transparent (as can be checked by mpl.colors.to_rgba); the ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/28153
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: rcParams[\"legend.labelcolor\"] treats \"none\" and \"None\" differently","articleBody":"### Bug summary\n\nThe \"standard\" matplotlib color semantics is that the strings `\"none\"` and `\"None\"` both mean fully transparent (as can be checked by mpl.colors.to_rgba); the object `None` can sometimes be used to mark a fallback. Because the matplotlibrc format cannot distinguish between `None` and `\"None\"` (due the use of unquoted strings), it normally uses \"auto\" or \"inherit\" to mark a fallback.\r\nHowever, `rcParams[\"legend.labelcolor\"]` (a relatively recent introduction -- matplotlib 3.5) tries to use \"None\" as default, and as a result ends up having inconsistent behavior between `\"None\"` and `\"none\"`.\n\n### Code for reproduction\n\n```Python\nfrom pylab import *\r\n\r\nrcdefaults()\r\nprint(repr(rcParams[\"legend.labelcolor\"]))\r\n# default is the string \"None\"\r\n\r\nrcParams[\"legend.labelcolor\"] = \"None\"; plot([0, 1], label=\"foo\"); legend()\r\n# labels are black\r\n\r\nrcParams[\"legend.labelcolor\"] = \"none\"; plot([0, 1], label=\"foo\"); legend()\r\n# labels are transparent\r\n\r\nrcParams[\"legend.labelcolor\"] = None; plot([0, 1], label=\"foo\"); legend()\r\n# labels are black\n```\n\n\n### Actual outcome\n\nSee above.\n\n### Expected outcome\n\n\"None\" and \"none\" should mean the same (likely both should mean \"transparent\", not so much for usefulness but rather for consistency.\n\n### Additional information\n\nI suspect trying to support the object `None` as well here basically cannot be made to work (as long as matplotlibrc uses unquoted strings); the default should switch to be \"auto\" (or \"inherit\").\r\n\r\nAs a further point, the implementation of the rcParams validator `_validate_color_or_linecolor` seems wrong:\r\n```python\r\n elif isinstance(s, str) and len(s) == 6 or len(s) == 8: # (1)\r\n stmp = '#' + s\r\n if is_color_like(stmp):\r\n return stmp\r\n if s.lower() == 'none': # (2)\r\n return None\r\n```\r\nLikely parentheses are missing at (1); also (2) can never hold due to the len() check.\r\nAs a side point, 3 and 4-hex color codes (\"abc(d)\", meaning \"#abc(d)\", meaning \"#aabbcc(dd)\") are also not supported by rcParams (this is also the case for the more general _validate_color), even though the normal color machinery does support them. At least this should be documented; I don't know if this can actually be supported without introducing an ambiguity with named colors.\n\n### Operating system\n\nmacos\n\n### Matplotlib Version\n\n3.9.0.dev1542+geb62d6951a\n\n### Matplotlib Backend\n\nany\n\n### Python version\n\n3.12\n\n### Jupyter version\n\nno\n\n### Installation\n\ngit checkout","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2024-04-30T14:19:13.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/28153/matplotlib/issues/28153"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7b873527-470d-ea66-a5b0-c7eafa07994e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 81B2:1078DB:9E0272:D2EA3F:6A52B530 |
| html-safe-nonce | 2e0ff1e262fa02f58c8cda6e9183cbe700ea985bc2b0bd3c49bbfb582caaaba7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUIyOjEwNzhEQjo5RTAyNzI6RDJFQTNGOjZBNTJCNTMwIiwidmlzaXRvcl9pZCI6IjcwMDY2NTg5ODUzMjA0Mjg4NDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d1676f094dd12f0deb6f6de4e82cfb47bd99911e1d6e2e9c2905722e18ad84ca |
| hovercard-subject-tag | issue:2271602101 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/28153/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a8ba39f483937d865f02098d753f4058c5852092f388c70b9f8b8917018d974a/matplotlib/matplotlib/issues/28153 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a8ba39f483937d865f02098d753f4058c5852092f388c70b9f8b8917018d974a/matplotlib/matplotlib/issues/28153 |
| og:image:alt | Bug summary The "standard" matplotlib color semantics is that the strings "none" and "None" both mean fully transparent (as can be checked by mpl.colors.to_rgba); the object None can sometimes be u... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anntzer |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width