Skip to content

Commit ddd82b5

Browse files
authored
Merge pull request #13211 from anntzer/case-sensitive-colors
Deprecate case-insensitive colors.
2 parents a2e2acf + aec2a56 commit ddd82b5

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Deprecations
2+
````````````
3+
4+
Support for passing colors as UPPERCASE strings is deprecated; color names will
5+
become case-sensitive (all-lowercase) after the deprecation period has passed.
6+
7+
The goal is to decrease the number of ambiguous cases when using the ``data``
8+
keyword to plotting methods; e.g. ``plot("X", "Y", data={"X": ..., "Y": ...})``
9+
will not warn about "Y" possibly being a color anymore after the deprecation
10+
period has passed.

lib/matplotlib/colors.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,17 @@ def _to_rgba_no_colorcycle(c, alpha=None):
194194
# Named color.
195195
try:
196196
# This may turn c into a non-string, so we check again below.
197-
c = _colors_full_map[c.lower()]
197+
c = _colors_full_map[c]
198198
except KeyError:
199-
pass
199+
try:
200+
c = _colors_full_map[c.lower()]
201+
except KeyError:
202+
pass
203+
else:
204+
cbook.warn_deprecated(
205+
"3.1", message="Support for case-insensitive colors is "
206+
"deprecated since Matplotlib %(since)s and will be "
207+
"removed %(removal)s.")
200208
if isinstance(c, str):
201209
# hex color with no alpha.
202210
match = re.match(r"\A#[a-fA-F0-9]{6}\Z", c)

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6036,3 +6036,11 @@ def test_annotate_across_transforms():
60366036
ax.annotate("", xy=(x[150], y[150]), xycoords=ax.transData,
60376037
xytext=(1, 0), textcoords=axins.transAxes,
60386038
arrowprops=dict(arrowstyle="->"))
6039+
6040+
6041+
def test_deprecated_uppercase_colors():
6042+
# Remove after end of deprecation period.
6043+
fig, ax = plt.subplots()
6044+
with pytest.warns(MatplotlibDeprecationWarning):
6045+
ax.plot([1, 2], color="B")
6046+
fig.canvas.draw()

0 commit comments

Comments
 (0)