Skip to content

Commit cbdec92

Browse files
committed
Switch the test to a non-picture one
1 parent cc1527c commit cbdec92

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed
Binary file not shown.

lib/matplotlib/tests/test_axes.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,28 +2909,32 @@ def test_eventplot_defaults():
29092909
colls = axobj.eventplot(data)
29102910

29112911

2912-
@image_comparison(baseline_images=['test_eventplot_colors'],
2913-
extensions=['png'], remove_text=True)
2914-
def test_eventplot_colors():
2915-
'''
2916-
Test that eventplot produces the correct output in several cases of
2917-
the *colors* parameter. Inspired by the issue #8193.
2912+
@pytest.mark.parametrize(('colors'), [
2913+
('0.5',), # string color with multiple characters: not OK before #8193 fix
2914+
('tab:orange', 'tab:pink', 'tab:cyan', 'bLacK'), # case-insensitive
2915+
('red', (0, 1, 0), None, (1, 0, 1, 0.5)), # a tricky case mixing types
2916+
('rgbk',) # len('rgbk') == len(data) and each character is a valid color
2917+
])
2918+
def test_eventplot_colors(colors):
2919+
'''Test the *colors* parameter of eventplot. Inspired by the issue #8193.
29182920
'''
29192921
data = [[i] for i in range(4)] # 4 successive events of different nature
29202922

2921-
fig, axs = plt.subplots(nrows=2, ncols=2)
2923+
# Build the list of the expected colors
2924+
expected = [c if c is not None else 'C0' for c in colors]
2925+
# Convert the list into an array of RGBA values
2926+
# NB: ['rgbk'] is not a valid argument for to_rgba_array, while 'rgbk' is.
2927+
if len(expected) == 1:
2928+
expected = expected[0]
2929+
expected = np.broadcast_to(mcolors.to_rgba_array(expected), (len(data), 4))
29222930

2923-
axs[0, 0].eventplot(data, colors='0.5') # not passing before #8193 fix
2924-
axs[0, 1].eventplot(data, colors=['tab:orange', 'tab:pink', 'tab:cyan',
2925-
'bLacK']) # should be case-insensitive
2926-
# A tricky case that mixes named, RGB, None and RGBA values
2927-
axs[1, 0].eventplot(data, colors=['red', (0, 1, 0), None, (1, 0, 1, 0.5)])
2928-
# Mostly a corner case, but it was passing even before the fix for #8193:
2929-
# len('rgbk') == len(data) and each single character is a valid color
2930-
axs[1, 1].eventplot(data, colors='rgbk')
2931+
fig, ax = plt.subplots()
2932+
if len(colors) == 1: # tuple with a single string (like '0.5' or 'rgbk')
2933+
colors = colors[0]
2934+
collections = ax.eventplot(data, colors=colors)
29312935

2932-
for ax in axs.flat:
2933-
ax.set_xlim(-0.1, 3.1) # avoid having some events on the axes edges
2936+
for coll, color in zip(collections, expected):
2937+
assert_allclose(coll.get_color(), color)
29342938

29352939

29362940
@image_comparison(baseline_images=['test_eventplot_problem_kwargs'],

0 commit comments

Comments
 (0)