Test the *colors* parameter of eventplot. Inspired by issue #8193.
(colors)
| 5493 | ('red', (0, 1, 0), None, (1, 0, 1, 0.5)), # a tricky case mixing types |
| 5494 | ]) |
| 5495 | def 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 | |
| 5516 | def test_eventplot_alpha(): |