8000 Add a non-picture test dedicated to the 'colors' parameter · matplotlib/matplotlib@c03df1f · GitHub
[go: up one dir, main page]

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 c03df1f

Browse files
committed
Add a non-picture test dedicated to the 'colors' parameter
1 parent e4fe239 commit c03df1f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

lib/matplotlib/tests/test_axes.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import matplotlib.colors as mcolors
2828
from numpy.testing import assert_allclose, assert_array_equal
2929
from matplotlib.cbook import IgnoredKeywordWarning
30+
from matplotlib.cbook._backports import broadcast_to
3031

3132
# Note: Some test cases are run twice: once normally and once with labeled data
3233
# These two must be defined in the same test function or need to have
@@ -2909,6 +2910,33 @@ def test_eventplot_defaults():
29092910
colls = axobj.eventplot(data)
29102911

29112912

2913+
@pytest.mark.parametrize(('colors'), [
2914+
('0.5',), # string color with multiple characters: not OK before #8193 fix
2915+
('tab:orange', 'tab:pink', 'tab:cyan', 'bLacK'), # case-insensitive
2916+
('red', (0, 1, 0), None, (1, 0, 1, 0.5)), # a tricky case mixing types
2917+
('rgbk',) # len('rgbk') == len(data) and each character is a valid color
2918+
])
2919+
def test_eventplot_colors(colors):
2920+
'''Test the *colors* parameter of eventplot. Inspired by the issue #8193.
2921+
'''
2922+
data = [[i] for i in range(4)] # 4 successive events of different nature
2923+
2924+
# Build the list of the expected colors
2925+
expected = [c if c is not None else 'C0' for c in colors]
2926+
# Convert the list into an array of RGBA values
2927+
# NB: ['rgbk'] is not a valid argument for to_rgba_array, while 'rgbk' is.
2928+
if len(expected) == 1:
2929+
expected = expected[0]
2930+
expected = broadcast_to(mcolors.to_rgba_array(expected), (len(data), 4))
2931+
2932+
fig, ax = plt.subplots()
2933+
if len(colors) == 1: # tuple with a single string (like '0.5' or 'rgbk')
2934+
colors = colors[0]
2935+
collections = ax.eventplot(data, colors=colors)
2936+
2937+
for coll, color in zip(collections, expected):
2938+
assert_allclose(coll.get_color(), color)
2939+
29122940
@image_comparison(baseline_images=['test_eventplot_problem_kwargs'],
29132941
extensions=['png'], remove_text=True)
29142942
def test_eventplot_problem_kwargs():

0 commit comments

Comments
 (0)
0