Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c3269a2

Browse files
committed
Fixed eventplot issues
1 parent 60163b5 commit c3269a2

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,9 +1313,6 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
13131313
else:
13141314
positions = [np.asanyarray(positions)]
13151315

1316-
if len(positions) == 0:
1317-
return []
1318-
13191316
poss = []
13201317
for position in positions:
13211318
poss += self._process_unit_info([("x", position)], kwargs)
@@ -1345,13 +1342,15 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
13451342
linewidths = np.asarray(linewidths)
13461343

13471344
if len(lineoffsets) == 0:
1348-
lineoffsets = [None]
1345+
raise ValueError('lineoffsets cannot be empty')
13491346
if len(linelengths) == 0:
1350-
linelengths = [None]
1351-
if len(linewidths) == 0:
1352-
lineoffsets = [None]
1347+
raise ValueError('linelengths cannot be empty')
1348+
if len(linestyles) == 0:
1349+
raise ValueError('linestyles cannot be empty')
13531350
if len(linewidths) == 0:
1354-
lineoffsets = [None]
1351+
raise ValueError('linewidths cannot be empty')
1352+
if len(alpha) == 0:
1353+
raise ValueError('alpha cannot be empty')
13551354
if len(colors) == 0:
13561355
colors = [None]
13571356
try:

lib/matplotlib/tests/test_axes.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6906,6 +6906,31 @@ def test_eventplot_legend():
69066906
plt.legend()
69076907

69086908

6909+
@pytest.mark.parametrize('err, args, kwargs, match', (
6910+
(ValueError, [[1]], {'lineoffsets': []}, 'lineoffsets cannot be empty'),
6911+
(ValueError, [[1]], {'linelengths': []}, 'linelengths cannot be empty'),
6912+
(ValueError, [[1]], {'linewidths': []}, 'linewidths cannot be empty'),
6913+
(ValueError, [[1]], {'linestyles': []}, 'linestyles cannot be empty'),
6914+
(ValueError, [[1]], {'alpha': []}, 'alpha cannot be empty'),
6915+
(ValueError, [1], {}, 'positions must be one-dimensional'),
6916+
(ValueError, [[1]], {'lineoffsets': [1, 2]},
6917+
'lineoffsets and positions are unequal sized sequences'),
6918+
(ValueError, [[1]], {'linelengths': [1, 2]},
6919+
'linelengths and positions are unequal sized sequences'),
6920+
(ValueError, [[1]], {'linewidths': [1, 2]},
6921+
'linewidths and positions are unequal sized sequences'),
6922+
(ValueError, [[1]], {'linestyles': [1, 2]},
6923+
'linestyles and positions are unequal sized sequences'),
6924+
(ValueError, [[1]], {'alpha': [1, 2]},
6925+
'alpha and positions are unequal sized sequences'),
6926+
(ValueError, [[1]], {'colors': [1, 2]},
6927+
'colors and positions are unequal sized sequences'),
6928+
))
6929+
def test_eventplot_errors(err, args, kwargs, match):
6930+
with pytest.raises(err, match=match):
6931+
plt.eventplot(*args, **kwargs)
6932+
6933+
69096934
def test_bar_broadcast_args():
69106935
fig, ax = plt.subplots()
69116936
# Check that a bar chart with a single height for all bars works.

0 commit comments

Comments
 (0)