Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9358c5c

Browse filesBrowse files
committed
Fix to_rgba_array() for empty input
1 parent f67d556 commit 9358c5c
Copy full SHA for 9358c5c

File tree

Expand file treeCollapse file tree

2 files changed

+6
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-3
lines changed

‎lib/matplotlib/colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colors.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ def to_rgba_array(c, alpha=None):
311311
cbook.warn_deprecated("3.2", message="Using a string of single "
312312
"character colors as a color sequence is "
313313
"deprecated. Use an explicit list instead.")
314-
else:
315-
result = np.array([to_rgba(cc, alpha) for cc in c])
314+
return result
316315

317-
return result
316+
if len(c) == 0:
317+
return np.zeros((0, 4), float)
318+
else:
319+
return np.array([to_rgba(cc, alpha) for cc in c])
318320

319321

320322
def to_rgb(c):

‎lib/matplotlib/tests/test_colors.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colors.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ def test_cn():
806806
def test_conversions():
807807
# to_rgba_array("none") returns a (0, 4) array.
808808
assert_array_equal(mcolors.to_rgba_array("none"), np.zeros((0, 4)))
809+
assert_array_equal(mcolors.to_rgba_array([]), np.zeros((0, 4)))
809810
# a list of grayscale levels, not a single color.
810811
assert_array_equal(
811812
mcolors.to_rgba_array([".2", ".5", ".8"]),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.