diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 52a41afeecd7..e712e1302544 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -1313,9 +1313,6 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1, else: positions = [np.asanyarray(positions)] - if len(positions) == 0: - return [] - poss = [] for position in positions: poss += self._process_unit_info([("x", position)], kwargs) @@ -1345,13 +1342,15 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1, linewidths = np.asarray(linewidths) if len(lineoffsets) == 0: - lineoffsets = [None] + raise ValueError('lineoffsets cannot be empty') if len(linelengths) == 0: - linelengths = [None] - if len(linewidths) == 0: - lineoffsets = [None] + raise ValueError('linelengths cannot be empty') + if len(linestyles) == 0: + raise ValueError('linestyles cannot be empty') if len(linewidths) == 0: - lineoffsets = [None] + raise ValueError('linewidths cannot be empty') + if len(alpha) == 0: + raise ValueError('alpha cannot be empty') if len(colors) == 0: colors = [None] try: diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 49bdc98abcb4..8ac3d9035992 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -6906,6 +6906,31 @@ def test_eventplot_legend(): plt.legend() +@pytest.mark.parametrize('err, args, kwargs, match', ( + (ValueError, [[1]], {'lineoffsets': []}, 'lineoffsets cannot be empty'), + (ValueError, [[1]], {'linelengths': []}, 'linelengths cannot be empty'), + (ValueError, [[1]], {'linewidths': []}, 'linewidths cannot be empty'), + (ValueError, [[1]], {'linestyles': []}, 'linestyles cannot be empty'), + (ValueError, [[1]], {'alpha': []}, 'alpha cannot be empty'), + (ValueError, [1], {}, 'positions must be one-dimensional'), + (ValueError, [[1]], {'lineoffsets': [1, 2]}, + 'lineoffsets and positions are unequal sized sequences'), + (ValueError, [[1]], {'linelengths': [1, 2]}, + 'linelengths and positions are unequal sized sequences'), + (ValueError, [[1]], {'linewidths': [1, 2]}, + 'linewidths and positions are unequal sized sequences'), + (ValueError, [[1]], {'linestyles': [1, 2]}, + 'linestyles and positions are unequal sized sequences'), + (ValueError, [[1]], {'alpha': [1, 2]}, + 'alpha and positions are unequal sized sequences'), + (ValueError, [[1]], {'colors': [1, 2]}, + 'colors and positions are unequal sized sequences'), +)) +def test_eventplot_errors(err, args, kwargs, match): + with pytest.raises(err, match=match): + plt.eventplot(*args, **kwargs) + + def test_bar_broadcast_args(): fig, ax = plt.subplots() # Check that a bar chart with a single height for all bars works.