diff --git a/doc/api/next_api_changes/2019-01-19-AL.rst b/doc/api/next_api_changes/2019-01-19-AL.rst new file mode 100644 index 000000000000..69fbe3cafc8e --- /dev/null +++ b/doc/api/next_api_changes/2019-01-19-AL.rst @@ -0,0 +1,10 @@ +Deprecations +```````````` + +Support for passing colors as UPPERCASE strings is deprecated; color names will +become case-sensitive (all-lowercase) after the deprecation period has passed. + +The goal is to decrease the number of ambiguous cases when using the ``data`` +keyword to plotting methods; e.g. ``plot("X", "Y", data={"X": ..., "Y": ...})`` +will not warn about "Y" possibly being a color anymore after the deprecation +period has passed. diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index bc99c69b2ed4..6b8653e4583b 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -194,9 +194,17 @@ def _to_rgba_no_colorcycle(c, alpha=None): # Named color. try: # This may turn c into a non-string, so we check again below. - c = _colors_full_map[c.lower()] + c = _colors_full_map[c] except KeyError: - pass + try: + c = _colors_full_map[c.lower()] + except KeyError: + pass + else: + cbook.warn_deprecated( + "3.1", message="Support for case-insensitive colors is " + "deprecated since Matplotlib %(since)s and will be " + "removed %(removal)s.") if isinstance(c, str): # hex color with no alpha. match = re.match(r"\A#[a-fA-F0-9]{6}\Z", c) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 1e549feda3d0..d64b01919918 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -6036,3 +6036,11 @@ def test_annotate_across_transforms(): ax.annotate("", xy=(x[150], y[150]), xycoords=ax.transData, xytext=(1, 0), textcoords=axins.transAxes, arrowprops=dict(arrowstyle="->")) + + +def test_deprecated_uppercase_colors(): + # Remove after end of deprecation period. + fig, ax = plt.subplots() + with pytest.warns(MatplotlibDeprecationWarning): + ax.plot([1, 2], color="B") + fig.canvas.draw()