Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d11b55f

Browse files
committed
Undeprecate case-insensitive "long" colornames.
CSS colors are case-insensitive (and typically given in CamelCase in CSS) so making them case-sensitive seems less than optimal and likely causes some pointless churn. Revert some corresponding changes in examples. Only keep the deprecation for single-letter colors, which are likely rarely given in uppercase (`plt.plot([1, 2], "Yo")` never worked and no one ever complained) and for which the rationale given in the changelog (collision with data-kwarg keys) remains valid. Update the docs to explicitly mention case-sensitivity.
1 parent aab3e8a commit d11b55f

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

doc/api/next_api_changes/2019-01-19-AL.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
Deprecations
22
````````````
33

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.
4+
Support for passing single-letter colors (one of "rgbcmykw") as UPPERCASE
5+
characters is deprecated; these colors will become case-sensitive (lowercase)
6+
after the deprecation period has passed.
67

78
The goal is to decrease the number of ambiguous cases when using the ``data``
89
keyword to plotting methods; e.g. ``plot("X", "Y", data={"X": ..., "Y": ...})``

examples/statistics/barchart_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828

2929
fig, ax = plt.subplots()
3030
rects1 = ax.bar(ind - width/2, men_means, width, yerr=men_std,
31-
color='skyblue', label='Men')
31+
color='SkyBlue', label='Men')
3232
rects2 = ax.bar(ind + width/2, women_means, width, yerr=women_std,
33-
color='indianred', label='Women')
33+
color='IndianRed', label='Women')
3434

3535
# Add some text for labels, title and custom x-axis tick labels, etc.
3636
ax.set_ylabel('Scores')

examples/ticks_and_spines/tick-locators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def setup(ax):
6666
# Index Locator
6767
ax = plt.subplot(n, 1, 5)
6868
setup(ax)
69-
ax.plot(range(0, 5), [0]*5, color='white')
69+
ax.plot(range(0, 5), [0]*5, color='White')
7070
ax.xaxis.set_major_locator(ticker.IndexLocator(base=.5, offset=.25))
7171
ax.text(0.0, 0.1, "IndexLocator(base=0.5, offset=0.25)",
7272
fontsize=14, transform=ax.transAxes)

lib/matplotlib/colors.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
:doc:`/tutorials/colors/colormapnorms` for more details about data
2727
normalization
2828
29-
More colormaps are available at palettable_
29+
More colormaps are available at palettable_.
3030
3131
The module also provides functions for checking whether an object can be
3232
interpreted as a color (:func:`is_color_like`), for converting such an object
@@ -37,27 +37,25 @@
3737
Matplotlib recognizes the following formats to specify a color:
3838
3939
* an RGB or RGBA tuple of float values in ``[0, 1]`` (e.g., ``(0.1, 0.2, 0.5)``
40-
or ``(0.1, 0.2, 0.5, 0.3)``);
41-
* a hex RGB or RGBA string (e.g., ``'#0F0F0F'`` or ``'#0F0F0F0F'``);
40+
or ``(0.1, 0.2, 0.5, 0.3)``);
41+
* a hex RGB or RGBA string (e.g., ``'#0F0F0F'`` or ``'#0f0f0f0f'``);
4242
* a string representation of a float value in ``[0, 1]`` inclusive for gray
4343
level (e.g., ``'0.5'``);
4444
* one of ``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``;
45-
* a X11/CSS4 color name;
46-
* a name from the `xkcd color survey <https://xkcd.com/color/rgb/>`__;
47-
prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``);
48-
* one of ``{'tab:blue', 'tab:orange', 'tab:green',
49-
'tab:red', 'tab:purple', 'tab:brown', 'tab:pink',
50-
'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the
51-
'T10' categorical palette (which is the default color cycle);
45+
* a X11/CSS4 color name (case-insensitive);
46+
* a name from the `xkcd color survey`_, prefixed with ``'xkcd:'`` (e.g.,
47+
``'xkcd:sky blue'``; case insensitive);
48+
* one of the Tableau Colors from the 'T10' categorical palette (the default
49+
color cycle): ``{'tab:blue', 'tab:orange', 'tab:green', 'tab:red',
50+
'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'}``
51+
(case-insensitive);
5252
* a "CN" color spec, i.e. `'C'` followed by a number, which is an index into
5353
the default property cycle (``matplotlib.rcParams['axes.prop_cycle']``); the
5454
indexing is intended to occur at rendering time, and defaults to black if the
5555
cycle does not include color.
5656
57-
All string specifications of color, other than "CN", are case-insensitive.
58-
5957
.. _palettable: https://jiffyclub.github.io/palettable/
60-
58+
.. _xkcd color survey: https://xkcd.com/color/rgb/
6159
"""
6260

6361
from collections.abc import Sized
@@ -201,10 +199,11 @@ def _to_rgba_no_colorcycle(c, alpha=None):
201199
except KeyError:
202200
pass
203201
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.")
202+
if len(c) == 1:
203+
cbook.warn_deprecated(
204+
"3.1", message="Support for case-insensitive "
205+
"single-letter colors is deprecated since Matplotlib "
206+
"%(since)s and will be removed %(removal)s.")
208207
if isinstance(c, str):
209208
# hex color with no alpha.
210209
match = re.match(r"\A#[a-fA-F0-9]{6}\Z", c)

tutorials/colors/colors.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@
55
66
Matplotlib recognizes the following formats to specify a color:
77
8-
* an RGB or RGBA tuple of float values in ``[0, 1]`` (e.g., ``(0.1, 0.2, 0.5)``
9-
or ``(0.1, 0.2, 0.5, 0.3)``). RGBA is short for Red, Green, Blue, Alpha;
10-
* a hex RGB or RGBA string (e.g., ``'#0F0F0F'`` or ``'#0F0F0F0F'``);
8+
* an RGB or RGBA (red, green, blue, alpha) tuple of float values in ``[0, 1]``
9+
(e.g., ``(0.1, 0.2, 0.5)`` or ``(0.1, 0.2, 0.5, 0.3)``);
10+
* a hex RGB or RGBA string (e.g., ``'#0F0F0F'`` or ``'#0f0f0f0f'``);
1111
* a string representation of a float value in ``[0, 1]`` inclusive for gray
1212
level (e.g., ``'0.5'``);
1313
* one of ``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``;
14-
* a X11/CSS4 color name;
15-
* a name from the `xkcd color survey <https://xkcd.com/color/rgb/>`__;
16-
prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``);
17-
* one of ``{'tab:blue', 'tab:orange', 'tab:green',
18-
'tab:red', 'tab:purple', 'tab:brown', 'tab:pink',
19-
'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the
20-
'T10' categorical palette (which is the default color cycle);
14+
* a X11/CSS4 color name (case-insensitive);
15+
* a name from the `xkcd color survey`_, prefixed with ``'xkcd:'`` (e.g.,
16+
``'xkcd:sky blue'``; case insensitive);
17+
* one of the Tableau Colors from the 'T10' categorical palette (the default
18+
color cycle): ``{'tab:blue', 'tab:orange', 'tab:green', 'tab:red',
19+
'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'}``
20+
(case-insensitive);
2121
* a "CN" color spec, i.e. `'C'` followed by a number, which is an index into
2222
the default property cycle (``matplotlib.rcParams['axes.prop_cycle']``); the
2323
indexing is intended to occur at rendering time, and defaults to black if the
2424
cycle does not include color.
2525
26-
"Red", "Green" and "Blue", are the intensities of those colors, the combination
26+
.. _xkcd color survey: https://xkcd.com/color/rgb/
27+
28+
"Red", "Green", and "Blue" are the intensities of those colors, the combination
2729
of which span the colorspace.
2830
2931
How "Alpha" behaves depends on the ``zorder`` of the Artist. Higher
@@ -36,8 +38,6 @@
3638
of 1 means the old color is completely covered by the new Artist, Alpha of 0
3739
means that pixel of the Artist is transparent.
3840
39-
All string specifications of color, other than "CN", are case-insensitive.
40-
4141
For more information on colors in matplotlib see
4242
4343
* the :doc:`/gallery/color/color_demo` example;

0 commit comments

Comments
 (0)