MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_eventplot_colors

Function test_eventplot_colors

lib/matplotlib/tests/test_axes.py:5495–5513  ·  view source on GitHub ↗

Test the *colors* parameter of eventplot. Inspired by issue #8193.

(colors)

Source from the content-addressed store, hash-verified

5493 ('red', (0, 1, 0), None, (1, 0, 1, 0.5)), # a tricky case mixing types
5494])
5495def test_eventplot_colors(colors):
5496 """Test the *colors* parameter of eventplot. Inspired by issue #8193."""
5497 data = [[0], [1], [2], [3]] # 4 successive events of different nature
5498
5499 # Build the list of the expected colors
5500 expected = [c if c is not None else 'C0' for c in colors]
5501 # Convert the list into an array of RGBA values
5502 # NB: ['rgbk'] is not a valid argument for to_rgba_array, while 'rgbk' is.
5503 if len(expected) == 1:
5504 expected = expected[0]
5505 expected = np.broadcast_to(mcolors.to_rgba_array(expected), (len(data), 4))
5506
5507 fig, ax = plt.subplots()
5508 if len(colors) == 1: # tuple with a single string (like '0.5' or 'rgbk')
5509 colors = colors[0]
5510 collections = ax.eventplot(data, colors=colors)
5511
5512 for coll, color in zip(collections, expected):
5513 assert_allclose(coll.get_color(), color)
5514
5515
5516def test_eventplot_alpha():

Callers

nothing calls this directly

Calls 3

eventplotMethod · 0.80
subplotsMethod · 0.45
get_colorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…