Skip to content

Fix eventplot colors kwarg #8861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 11, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add a non-picture test dedicated to the 'colors' parameter
  • Loading branch information
afvincent authored and tacaswell committed Jul 11, 2017
commit 79c00e9900dc1ad4c06a45484cb3d232b277e282
28 changes: 28 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import matplotlib.colors as mcolors
from numpy.testing import assert_allclose, assert_array_equal
from matplotlib.cbook import IgnoredKeywordWarning
from matplotlib.cbook._backports import broadcast_to

# Note: Some test cases are run twice: once normally and once with labeled data
# These two must be defined in the same test function or need to have
Expand Down Expand Up @@ -2985,6 +2986,33 @@ def test_eventplot_defaults():
colls = axobj.eventplot(data)


@pytest.mark.parametrize(('colors'), [
('0.5',), # string color with multiple characters: not OK before #8193 fix
('tab:orange', 'tab:pink', 'tab:cyan', 'bLacK'), # case-insensitive
('red', (0, 1, 0), None, (1, 0, 1, 0.5)), # a tricky case mixing types
('rgbk',) # len('rgbk') == len(data) and each character is a valid color
])
def test_eventplot_colors(colors):
'''Test the *colors* parameter of eventplot. Inspired by the issue #8193.
'''
data = [[i] for i in range(4)] # 4 successive events of different nature

# Build the list of the expected colors
expected = [c if c is not None else 'C0' for c in colors]
# Convert the list into an array of RGBA values
# NB: ['rgbk'] is not a valid argument for to_rgba_array, while 'rgbk' is.
if len(expected) == 1:
expected = expected[0]
expected = broadcast_to(mcolors.to_rgba_array(expected), (len(data), 4))

fig, ax = plt.subplots()
if len(colors) == 1: # tuple with a single string (like '0.5' or 'rgbk')
colors = colors[0]
collections = ax.eventplot(data, colors=colors)

for coll, color in zip(collections, expected):
assert_allclose(coll.get_color(), color)

@image_comparison(baseline_images=['test_eventplot_problem_kwargs'],
extensions=['png'], remove_text=True)
def test_eventplot_problem_kwargs():
Expand Down