Skip to content

Commit 3191099

Browse files
authored
Merge pull request #13134 from anntzer/colorconverter
Simplify color conversion backcompat shim.
2 parents 4cdc2ba + 9ec8264 commit 3191099

File tree

1 file changed

+5
-50
lines changed

1 file changed

+5
-50
lines changed

lib/matplotlib/colors.py

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -305,60 +305,15 @@ def to_hex(c, keep_alpha=False):
305305

306306
class ColorConverter(object):
307307
"""
308-
Provides methods for converting color specifications to *RGB* or *RGBA*
308+
This class is only kept for backwards compatibility.
309309
310-
Caching is used for more efficient conversion upon repeated calls
311-
with the same argument.
312-
313-
Ordinarily only the single instance instantiated in this module,
314-
*colorConverter*, is needed.
310+
Its functionality is entirely provided by module-level functions.
315311
"""
316-
317312
colors = _colors_full_map
318313
cache = _colors_full_map.cache
319-
320-
@staticmethod
321-
def to_rgb(arg):
322-
"""
323-
Returns an *RGB* tuple of three floats from 0-1.
324-
325-
*arg* can be an *RGB* or *RGBA* sequence or a string in any of
326-
several forms:
327-
328-
1) a letter from the set 'rgbcmykw'
329-
2) a hex color string, like '#00FFFF'
330-
3) a standard name, like 'aqua'
331-
4) a string representation of a float, like '0.4',
332-
indicating gray on a 0-1 scale
333-
334-
if *arg* is *RGBA*, the *A* will simply be discarded.
335-
"""
336-
return to_rgb(arg)
337-
338-
@staticmethod
339-
def to_rgba(arg, alpha=None):
340-
"""
341-
Returns an *RGBA* tuple of four floats from 0-1.
342-
343-
For acceptable values of *arg*, see :meth:`to_rgb`.
344-
In addition, if *arg* is "none" (case-insensitive),
345-
then (0,0,0,0) will be returned.
346-
If *arg* is an *RGBA* sequence and *alpha* is not *None*,
347-
*alpha* will replace the original *A*.
348-
"""
349-
return to_rgba(arg, alpha)
350-
351-
@staticmethod
352-
def to_rgba_array(arg, alpha=None):
353-
"""
354-
Returns a numpy array of *RGBA* tuples.
355-
356-
Accepts a single mpl color spec or a sequence of specs.
357-
358-
Special case to handle "no color": if *c* is "none" (case-insensitive),
359-
then an empty array will be returned. Same for an empty list.
360-
"""
361-
return to_rgba_array(arg, alpha)
314+
to_rgb = staticmethod(to_rgb)
315+
to_rgba = staticmethod(to_rgba)
316+
to_rgba_array = staticmethod(to_rgba_array)
362317

363318

364319
colorConverter = ColorConverter()

0 commit comments

Comments
 (0)