Skip to content

Commit fee28d0

Browse files
committed
Remove use of colorConverter.
Except in Qt options editor, which is under a separate PR. This also makes it possible to call plt.plot([1, 2, 3], "#ff000040") (setting alpha at the same time).
1 parent 8ff6673 commit fee28d0

26 files changed

+106
-164
lines changed

examples/api/collections_demo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
'''
1818

1919
import matplotlib.pyplot as plt
20-
from matplotlib import collections, transforms
21-
from matplotlib.colors import colorConverter
20+
from matplotlib import collections, colors, transforms
2221
import numpy as np
2322

2423
nverts = 50
@@ -38,7 +37,7 @@
3837
xyo = list(zip(xo, yo))
3938

4039
# Make a list of colors cycling through the default series.
41-
colors = [colorConverter.to_rgba(c)
40+
colors = [colors.to_rgba(c)
4241
for c in plt.rcParams['axes.prop_cycle'].by_key()['color']]
4342

4443
fig, axes = plt.subplots(2, 2)

examples/event_handling/lasso_demo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
usable as is). There will be some refinement of the API.
88
"""
99
from matplotlib.widgets import Lasso
10-
from matplotlib.colors import colorConverter
1110
from matplotlib.collections import RegularPolyCollection
12-
from matplotlib import path
11+
from matplotlib import colors as mcolors, path
1312

1413
import matplotlib.pyplot as plt
1514
from numpy import nonzero
1615
from numpy.random import rand
1716

1817

1918
class Datum(object):
20-
colorin = colorConverter.to_rgba('red')
21-
colorout = colorConverter.to_rgba('blue')
19+
colorin = mcolors.to_rgba("red")
20+
colorout = mcolors.to_rgba("blue")
2221

2322
def __init__(self, x, y, include=False):
2423
self.x = x

examples/mplot3d/polys3d_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
from mpl_toolkits.mplot3d import Axes3D
77
from matplotlib.collections import PolyCollection
8-
from matplotlib.colors import colorConverter
98
import matplotlib.pyplot as plt
9+
from matplotlib import colors as mcolors
1010
import numpy as np
1111

1212

1313
def cc(arg):
1414
'''
1515
Shorthand to convert 'named' colors to rgba format at 60% opacity.
1616
'''
17-
return colorConverter.to_rgba(arg, alpha=0.6)
17+
return mcolors.to_rgba(arg, alpha=0.6)
1818

1919

2020
def polygon_under_graph(xlist, ylist):

examples/pylab_examples/colours.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Some simple functions to generate colours.
44
"""
55
import numpy as np
6-
from matplotlib.colors import colorConverter
6+
from matplotlib import colors as mcolors
77

88

99
def pastel(colour, weight=2.4):
1010
""" Convert colour into a nice pastel shade"""
11-
rgb = np.asarray(colorConverter.to_rgb(colour))
11+
rgb = np.asarray(mcolors.to_rgba(colour)[:3])
1212
# scale colour
1313
maxc = max(rgb)
1414
if maxc < 1.0 and maxc > 0:

examples/pylab_examples/demo_ribbon_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RibbonBox(object):
1818
nx = original_image.shape[1]
1919

2020
def __init__(self, color):
21-
rgb = matplotlib.colors.colorConverter.to_rgb(color)
21+
rgb = matplotlib.colors.to_rgba(color)[:3]
2222

2323
im = np.empty(self.original_image.shape,
2424
self.original_image.dtype)

examples/pylab_examples/line_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import matplotlib.pyplot as plt
22
from matplotlib.collections import LineCollection
3-
from matplotlib.colors import colorConverter
3+
from matplotlib import colors as mcolors
44

55
import numpy as np
66

@@ -30,7 +30,7 @@
3030
# where onoffseq is an even length tuple of on and off ink in points.
3131
# If linestyle is omitted, 'solid' is used
3232
# See matplotlib.collections.LineCollection for more information
33-
colors = [colorConverter.to_rgba(c)
33+
colors = [mcolors.to_rgba(c)
3434
for c in plt.rcParams['axes.prop_cycle'].by_key()['color']]
3535

3636
line_segments = LineCollection(segs, linewidths=(0.5, 1, 1.5, 2),

examples/widgets/menu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def __init__(self, fontsize=14, labelcolor='black', bgcolor='yellow',
1717
self.bgcolor = bgcolor
1818
self.alpha = alpha
1919

20-
self.labelcolor_rgb = colors.colorConverter.to_rgb(labelcolor)
21-
self.bgcolor_rgb = colors.colorConverter.to_rgb(bgcolor)
20+
self.labelcolor_rgb = colors.to_rgba(labelcolor)[:3]
21+
self.bgcolor_rgb = colors.to_rgba(bgcolor)[:3]
2222

2323

2424
class MenuItem(artist.Artist):

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ def make_iterable(x):
20652065
if color is None:
20662066
color = [None] * nbars
20672067
else:
2068-
color = list(mcolors.colorConverter.to_rgba_array(color))
2068+
color = list(mcolors.to_rgba_array(color))
20692069
if len(color) == 0: # until to_rgba_array is changed
20702070
color = [[0, 0, 0, 0]]
20712071
if len(color) < nbars:
@@ -2074,7 +2074,7 @@ def make_iterable(x):
20742074
if edgecolor is None:
20752075
edgecolor = [None] * nbars
20762076
else:
2077-
edgecolor = list(mcolors.colorConverter.to_rgba_array(edgecolor))
2077+
edgecolor = list(mcolors.to_rgba_array(edgecolor))
20782078
if len(edgecolor) == 0: # until to_rgba_array is changed
20792079
edgecolor = [[0, 0, 0, 0]]
20802080
if len(edgecolor) < nbars:
@@ -3846,7 +3846,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
38463846
co = kwargs.pop('color', None)
38473847
if co is not None:
38483848
try:
3849-
mcolors.colorConverter.to_rgba_array(co)
3849+
mcolors.to_rgba_array(co)
38503850
except ValueError:
38513851
raise ValueError("'color' kwarg must be an mpl color"
38523852
" spec or sequence of color specs.\n"
@@ -6045,7 +6045,7 @@ def _normalize_input(inp, ename='input'):
60456045
if color is None:
60466046
color = [self._get_lines.get_next_color() for i in xrange(nx)]
60476047
else:
6048-
color = mcolors.colorConverter.to_rgba_array(color)
6048+
color = mcolors.to_rgba_array(color)
60496049
if len(color) != nx:
60506050
raise ValueError("color kwarg must have one color per dataset")
60516051

lib/matplotlib/axes/_base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _process_plot_format(fmt):
6868

6969
# Is fmt just a colorspec?
7070
try:
71-
color = mcolors.colorConverter.to_rgb(fmt)
71+
color = mcolors.to_rgba(fmt)
7272

7373
# We need to differentiate grayscale '1.0' from tri_down marker '1'
7474
try:
@@ -112,14 +112,14 @@ def _process_plot_format(fmt):
112112
raise ValueError(
113113
'Illegal format string "%s"; two marker symbols' % fmt)
114114
marker = c
115-
elif c in mcolors.colorConverter.colors:
115+
elif c in mcolors.get_named_colors_mapping():
116116
if color is not None:
117117
raise ValueError(
118118
'Illegal format string "%s"; two color symbols' % fmt)
119119
color = c
120120
elif c == 'C' and i < len(chars) - 1:
121121
color_cycle_number = int(chars[i + 1])
122-
color = mcolors.colorConverter._get_nth_color(color_cycle_number)
122+
color = mcolors.to_rgba("C{}".format(color_cycle_number))
123123
i += 1
124124
else:
125125
raise ValueError(
@@ -3687,7 +3687,7 @@ def set_cursor_props(self, *args):
36873687
lw, c = args
36883688
else:
36893689
raise ValueError('args must be a (linewidth, color) tuple')
3690-
c = mcolors.colorConverter.to_rgba(c)
3690+
c = mcolors.to_rgba(c)
36913691
self._cursorProps = lw, c
36923692

36933693
def get_children(self):

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,11 +1022,11 @@ def set_foreground(self, fg, isRGBA=False):
10221022
if self._forced_alpha and isRGBA:
10231023
self._rgb = fg[:3] + (self._alpha,)
10241024
elif self._forced_alpha:
1025-
self._rgb = colors.colorConverter.to_rgba(fg, self._alpha)
1025+
self._rgb = colors.to_rgba(fg, self._alpha)
10261026
elif isRGBA:
10271027
self._rgb = fg
10281028
else:
1029-
self._rgb = colors.colorConverter.to_rgba(fg)
1029+
self._rgb = colors.to_rgba(fg)
10301030

10311031
def set_graylevel(self, frac):
10321032
"""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy